Write Components. Read an undirected graph: n m, then m edges u v (vertices 0 … n − 1), then pairs a b to test. Using BFS (or DFS) from every not-yet-visited vertex in increasing order, label each vertex with its component. Print each component (vertices sorted), the number of components and the size of the largest, whether the graph is connected, how many edges would be needed to connect everything, and for each pair whether the two vertices are connected.
For the input
8 5
0 1
1 2
3 4
5 6
6 5
0 2 3 5 7 7
the program prints
Component 1: [0, 1, 2]
Component 2: [3, 4]
Component 3: [5, 6]
Component 4: [7]
Components: 4, largest has 3 vertices
Connected graph: false
Edges needed to connect everything: 3
0 and 2 connected: true
3 and 5 connected: false
7 and 7 connected: true