AlgoUniversity
  • Go Back
Discussion
Connecting The Special Nodes :

Author

Akshay Sharma

Difficulty Level : Hard

Submissions : 95

Asked In : Gameskraft

Marks :100

: 1 | : 0

You are given a graph of N nodes. The graph consists of connected components. Some of the connected components contain a special node and each component contains at most one special node. You are required to maximize the number of edges in the given graph such that it follows these constraints:

No self-loop or multiple edges should be present No connected components with more than one special node should be present

Each node in the graph should belong to a component with exactly one special node

If you add an edge between two nodes that belong to the same component in the graph, then the total cost involved is 0. Whereas, if you connect two nodes that belong to different components, then the cost is equal to the product of the sizes of both components.

Your task is to maximize the number of new edges in the graph and calculate the minimum cost that will be involved in performing the required task.

Input

First line: Three integers N,M,K representing the number of nodes, number of edges, and number of special nodes in the graph respectively ($$$1 \le N \le 10^5$$$)and ($$$1 \le N \le 20^5$$$)

Next M lines: Two integers representing an undirected edge from the node u to node v

Next line: K space-separated integers each representing the special nodes in a connected component

Output

Print the maximum number of new edges that can be added to the graph and the minimum cost of doing so.

Example

Input
12 7 2
1 2
1 3
4 5
4 6
5 7
9 10
11 12
1 4
Output
32 28

Note

K $$$\le$$$ the total number of connected components present in the graph.

It is guaranteed that for any connected component at most one special node exists.

The given graph does not contain any self-loops or multiple edges.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.