# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
405191 | T0p_ | Network (BOI15_net) | C++14 | 0 ms | 0 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 sz;
vector<int> g[500005], leaf;
void dfs(int u, int p)
{
if(g[u].size() == 1) leaf.push_back(u), sz++;
for(auto x : g[u]) if(x != p) dfs(x, u);
}
int main()
{
int n;
scanf(" %d",&n);
for(int i=1 ; i<n ; i++)
{
int u, v;
scanf(" %d %d",&u,&v);
g[u].push_back(v), g[v].push_back(u);
}
dfs(1, 0);
printf("%d\n",(sz+1)/2);
for(int i=0 ; i<sz ; i+=2)
printf("%d %d\n",v[i],v[i+1]);
if(sz%2) printf("%d %d\n",v[sz-1],v[0]);
return 0;
}