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>
#define DIM 500010
using namespace std;
vector <int> L[DIM],v;
int g[DIM];
int n,i,j,x,y,rad;
void dfs (int nod, int tata){
int ok = 0;
for (auto vecin : L[nod])
if (vecin != tata){
ok = 1;
dfs (vecin,nod);
}
if (!ok)
v.push_back(nod);
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n;
for (i=1;i<n;i++){
cin>>x>>y;
L[x].push_back(y);
L[y].push_back(x);
g[x]++, g[y]++;
}
for (i=1;i<=n;i++)
if (g[i] >= 2){
rad = i;
break;
}
dfs (rad,0);
cout<<(v.size()+1)/2<<"\n";
if (v.size() % 2){
cout<<v.back()<<" "<<rad<<"\n";
v.pop_back();
}
i = 0, j = v.size()-1;
while (i < j){
cout<<v[i]<<" "<<v[j]<<"\n";
i++, j--;
}
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... |