#DSU0000015. Những con đường ở Berland (Roads not only in Berland)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những con đường ở Berland (Roads not only in Berland)
Roads not only in Berland
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Berland has cities and exactly bidirectional roads, but the road network need not be connected. In one day, you may remove an existing road and build a new road between two cities.
Find the minimum number of days required to make all cities connected and output a valid plan.
Input
The first line contains an integer . Each of the next lines contains two integers describing an existing road. Cities are numbered from to .
Output
Print the minimum number of days on the first line. For each day, print four integers : remove road and build road . Any optimal valid plan is accepted.
Subtasks
- Subtask 1 (20 points): ; exactly edges; ; ; no repeated edges.
- Subtask 2 (30 points): ; exactly edges; ; ; no repeated edges.
- Subtask 3 (50 points): ; exactly edges; ; ; no repeated edges.
Examples
Input
7
1 2
2 3
3 1
4 5
5 6
6 7
Output
1
3 1 1 4
Explanation
Vertices 1,2,3 form a cycle: one edge can be removed without disconnecting its component, then used to connect the other component in one day.