Graph Connectivity
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 122.174 megabytes
You are given a graph with n vertices and m edges, where 1 ≤ n ≤ 1000 and 1 ≤ m ≤ 7000.
Your task is to determine the minimum number of edges that must be added to make the graph connected, and specify these edges.
Input
The input begins with the integers n and m, followed by m pairs of integers. Each pair represents an edge in the graph, indicating the start and end vertices of that edge.
Output
First, output the minimum number of edges k that need to be added. Then, for the next k lines, provide the two vertices that form each new edge.
Examples
Input #1
Answer #1
Submissions 281
Acceptance rate 52%