# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226273 | MKopchev | Network (BOI15_net) | C++14 | 519 ms | 45300 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;
const int nmax=5e5+42;
int n;
vector<int> adj[nmax];
vector<int> leaves;
void dfs(int node,int par)
{
if(adj[node].size()==1)leaves.push_back(node);
for(auto k:adj[node])
if(k!=par)dfs(k,node);
}
int main()
{
scanf("%i",&n);
int u,v;
for(int i=1;i<n;i++)
{
scanf("%i%i",&u,&v);
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++)
if(adj[i].size()>=2)
{
dfs(i,0);
break;
}
int output=(leaves.size()+1)/2;
printf("%i\n",output);
int step=leaves.size()-output;
for(int i=0;i<output;i++)
{
printf("%i %i\n",leaves[i],leaves[i+step]);
}
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... |