Graph Connectivity#5135

Graph Connectivity

1 segundo
122,174 megabytes
Muy fácil

You are given a graph with vertices and edges, where 1 \leq n \leq 1000 and 1 \leq m \leq 7000.

Your task is to determine the minimum number of edges that must be added to make the graph connected, and specify these edges.

Entrada

The input begins with the integers and , followed by pairs of integers. Each pair represents an edge in the graph, indicating the start and end vertices of that edge.

Salida

First, output the minimum number of edges that need to be added. Then, for the next lines, provide the two vertices that form each new edge.

Ejemplos

Ejemplo 1

Loading
Loading