# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32311 | dqhungdl | Network (BOI15_net) | C++14 | 6 ms | 14384 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;
typedef pair<int,int> ii;
int n;
bool Free[500005];
vector<int> V,g[500005];
vector<ii> rs;
void DFS(int u)
{
Free[u]=true;
if(g[u].size()==1)
{
V.push_back(u);
return;
}
for(int i=0;i<g[u].size();i++)
if(Free[g[u][i]]==false)
DFS(g[u][i]);
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("NET.INP","r",stdin);
cin>>n;
int u,v;
for(int i=1;i<n;i++)
{
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i=1;i<=n;i++)
if(g[i].size()>=2)
{
DFS(i);
break;
}
cout<<(V.size()+1)/2<<"\n";
for(int i=0;i<=(V.size()-1)/2;i++)
cout<<V[i]<<' '<<V[i+V.size()/2]<<"\n";
}
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... |