PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000004. Xây thêm đường (Building Roads)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xây thêm đường (Building Roads)

Building Roads

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

A country has nn cities and mm bidirectional roads. Build the minimum number of additional roads so that every city can be reached from every other city.

Input

The first line contains two integers n,mn,m. Each of the next mm lines contains two integers a,ba,b, describing a bidirectional road between cities aa and bb. Cities are numbered from 11 to nn.

Output

Print the minimum number kk of new roads on the first line. Then print kk lines, each containing the endpoints of a new road. Any valid optimal construction is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1501\le n\le 150; 1≤m≤1701\le m\le 170; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no two existing roads connect the same pair of cities.
  • Subtask 2 (30 points): 1≤n≤100001\le n\le 10000; 1≤m≤60001\le m\le 6000; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no two existing roads connect the same pair of cities.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤m≤2000001\le m\le 200000; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no two existing roads connect the same pair of cities.

Examples

Input

4 2
1 2
3 4

Output

1
1 3

Explanation

The original components are {1,2} and {3,4}. One edge between them is sufficient.