# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51613 | okaybody10 | Network (BOI15_net) | C++98 | 673 ms | 155376 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;
vector<int> v[600005],ans;
void dfs(int e,int s)
{
if(v[e].size()==1) { ans.push_back(e); return; }
int sz=v[e].size();
for(int i=0;i<sz;i++)
{
if(v[e][i]==s) continue;
dfs(v[e][i],e);
}
}
int main()
{
int n; scanf("%d",&n);
for(int i=0;i<n-1;i++)
{
int x,y; scanf("%d %d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
int firstdfs;
for(int i=1;i<=n;i++) if(v[i].size()>=2) { firstdfs=i; break;}
dfs(firstdfs,-1);
int sz=ans.size();
printf("%d\n",sz/2+sz%2);
for(int i=0;i+sz/2<sz;i++) printf("%d %d\n",ans[i],ans[i+sz/2]);
return 0;
}
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... |