So NP
Algorithms
Easy
Graphs
92.0% success
15,809 attempts
2s time
256MB memory
1024KB max code

Once a upon time a problem setter offered a problem to Arpa. Like always Arpa said "eaaasy", but after a time Arpa said this problem is so NP.

Solve this problem to prove Arpa is always right and his first opinion is correct.

You are given a graph with $$n$$ nodes and $$m$$ edges.
Calculate maximum number of edges that can be removed from the graph so that it contains exactly $$k$$ connected components.


Input

The first line contains $$n, m, k$$(in order).
The next m lines have $$2$$ number,$$u_i$$ and $$v_i$$ that showS there is an edge between those nodes.
It is guaranteed that input is valid(no multiple edges and no loops).

 

Output

Maximum number of edges that can be removed from the graph such that it contains exactly $$k$$ connected components.
If the graph intially has more than $$k$$ components print $$-1$$. 

 

Constraints

$$1 \le n, m \le 100\ 000$$
$$1 \le k \le n$$

Examples
Input
4 3 2
1 2
2 3
1 3
Output
1
Explanation

Initially, the graph has \(2\) connected components, hence we can remove only \(1\) edge.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...