# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
106891 | Pajaraja | Network (BOI15_net) | C++17 | 735 ms | 47688 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> g[500007];
int k[500007],cnt;
void dfs(int s,int f)
{
if(g[s].size()==1) {k[cnt++]=s; return;}
for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s);
}
int main()
{
int n,v1,v2,l=0;
scanf("%d",&n);
for(int i=0;i<n-1;i++)
{
scanf("%d%d",&v1,&v2);
g[v1].push_back(v2);
g[v2].push_back(v1);
}
for(int i=1;i<=n;i++) if(g[i].size()==1) l++;
printf("%d\n",(l+1)/2);
for(int i=1;i<=n;i++) if(g[i].size()>1)
{
dfs(i,0);
for(int j=0;j<l/2;j++) printf("%d %d\n",k[j],k[j+(l+1)/2]);
if(l%2==1) printf("%d %d",i,k[l/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... |