eolymp
bolt
Try our new interface for solving problems
Məsələlər

Plunder & Flee - 2

Plunder & Flee - 2

Hacker Kirill successfully coped with the task that "Plunder & Flee Inc." management had set before him last year, and he was transferred to the central office. Now he faces a new challenge of improving the computer network in the central office. The network consists of \textbf{n} workstations coupled by \textbf{n--1} network cables; each pair of workstations has at most a single connection. Information is relayed between stations until it reaches the recipient. Currently, the network is set up in such a way that only a single route exists between any two stations. The solution is cheap but it has a major shortcoming: any cable failure renders the network inoperable. The management asked Kirill to improve the network using the least possible number of additional cables so as to keep the network operational in case of a single cable failure. Write a program that, given the network structure, will determine the minimum number of additional cables necessary to improve the network as described above. \InputFile The first line of the input file contains integer \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{1000}), the number of workstations in the network. The following \textbf{n--1} lines describe the communication links. They contain space-delimited numbers of workstations connected by cable \textbf{i}: integers \textbf{a_i} and \textbf{b_i} (\textbf{1} ≤ \textbf{a_i}, \textbf{b_i} ≤ \textbf{n}). The workstations are identified with natural numbers ranging from \textbf{1} to \textbf{n}. \OutputFile The first line of the output file should contain integer \textbf{m}, the number of additional cables. Then \textbf{m} lines should follow, each consisting of a space-delimited pair of integers denoting the numbers of newly connected stations.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3
1 2
2 3
Çıxış verilənləri #1
1
1 3
Mənbə 2013-2014 ACM Central Region of Russia Quarterfinal, Rybinsk 2013/10/17