#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
long long n,t1,t2;
cin >> n;
vector<long long> net(n + 1,0);
vector<vector<long long>> conwith(n + 1);
vector<long long> con;
for(long long i = 1; i < n; i++){
cin >> t1 >> t2;
net[t1]++;
net[t2]++;
conwith[t1].emplace_back(t2);
conwith[t2].emplace_back(t1);
}
long long c = 0;
for(long long i = 1; i < net.size(); i++){
if(net[i] == 1){
c++;
con.emplace_back(i);
}
}
if(c % 2 == 1){
c /= 2;
c += 1;
}
else{
c /= 2;
}
cout << c << '\n';
while(con.size() > 1){
t1 = con.back();
con.pop_back();
t2 = con.back();
con.pop_back();
cout << t1 << ' ' << t2 << '\n';
}
if(con.size() == 1){
cout << con.back() << ' ';
for(long long i = 1; i < net.size(); i++){
if(i != con.back() && find(conwith[con.back()].begin(),conwith[con.back()].end(),i) == conwith[con.back()].end()){
cout << i << '\n';
break;
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |