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;
const int MAXN = 5e5 + 100;
int grau[MAXN];
int main(){
int n;
cin >> n;
for(int i=1; i<n; i++){
int a, b;
cin >> a >> b;
grau[a]++;
grau[b]++;
}
vector<int> v;
for(int i=1; i<=n; i++){
if(grau[i]==1){
v.push_back(i);
}
}
int ans = (v.size()+1)/2;
cout << ans << "\n";
for(int i=0; i<ans-1; i++){
cout << v[i] << " " << v[i+ans] << "\n";
}
if(v.size()&1){
cout << v[ans-1] << " " << v[0] << "\n";
}
else{
cout << v[ans-1] << " " << v[v.size()-1];
}
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... |