This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int deg[100005];
int main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i=1;i<n;i++){
int u,v;
cin >> u >> v;
deg[u]++; deg[v]++;
}
int cnt=0;
for (int i=1;i<=n;i++){
if (deg[i] == 1) cnt++;
}
cout << (cnt+1)/2 << "\n";
int node=0;
for (int i=1;i<=n;i++){
if (deg[i] == 1){
if (node == 0) node=i;
else{
cout << node << " " << i << "\n";
node=0;
}
}
}
for (int i=1;i<=n;i++){
if (deg[i] == 1 && node != 0){
cout << node << " " << i << "\n";
break;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |