# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203572 | mdn2002 | Network (BOI15_net) | C++14 | 1172 ms | 47732 KiB |
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 n;
vector<int>lf,gr[500005];
void dfs(int x,int p)
{
if(gr[x].size()==1)lf.push_back(x);
for(int i=0;i<gr[x].size();i++)
{
int u=gr[x][i];
if(u==p)continue;
dfs(u,x);
}
}
int main()
{
cin>>n;
for(int i=0;i<n-1;i++)
{
int x,y;
cin>>x>>y;
gr[x].push_back(y);
gr[y].push_back(x);
}
dfs(1,0);
cout<<lf.size()/2+(lf.size()%2)<<endl;
for(int i=0;i<lf.size()/2;i++)
{
cout<<lf[i]<<' '<<lf[i+(lf.size()/2)]<<endl;
}
if(lf.size()%2)cout<<lf[0]<<' '<<lf[lf.size()-1]<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |