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 pii pair<int,int>
#define ll long long
#define s second
using namespace std;
const int mxn=5e5+6;
vector<int> tree[mxn];
vector<int> lf;
int root=1;
void dfs(int cur,int prev)
{
if(tree[cur].size()==1)lf.push_back(cur);
for(int i:tree[cur])
{
if(i!=prev)
{
dfs(i,cur);
}
}
}
int main()
{
int n;
cin>>n;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
tree[u].push_back(v);
tree[v].push_back(u);
}
dfs(root,-1);
int r=lf.size();
cout<<(r+1)/2<<endl;
int md=(r+1)/2;
for(int i=0;i<md;i++)
{
if(i+md<r)
cout<<lf[i]<<" "<<lf[i+md]<<endl;
else
cout<<lf[i]<<" "<<lf[r-1]<<endl;
}
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... |