题目描述
You are given a graph with n vertices and m edges.
You can remove one edge from anywhere and add that edge between any two vertices in one operation.
Find the minimum number of operation that will be required to make the graph connected.
If it is not possible to make the graph connected, return -1.
Example 1:
Input:
n=4
m=3
Edge=[ [0, 1] , [0, 2] , [1, 2] ]
Output:
1
Explanation:
Remove edge between vertices 1 and 2 and add between vertices 1 and 3.
Example 2:
Input:
n=6
m=5
Edge=[ [0,1] , [0,2] , [0,3] , [1,2] , [1,3] ]
Output:
2
Explanation:
Remove edge between (1,2) and(0,3) and add edge between (1,4) and (3,5)
Your Task:
You don't need to read or print anything. Your task is to complete the function Solve() which takes an integer n denoting no. of vertices and a matrix edge[][] denoting the the edges of graph and return the minimum number of operation to connect a graph
Constraints:
1<=n<=10^{5}
0<=m<=10^{5}
0<=edge[i][0],edge[i][1]
输入格式
见题面
输出格式
见题面