# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
311448 | vipghn2003 | Network (BOI15_net) | C++14 | 10 ms | 12032 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 N=5e5+5;
int n;
vector<int>leaf;
vector<int>adj[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++) if(adj[i].size()==1) leaf.push_back(i);
cout<<(leaf.size()+1)/2<<'\n';
for(int i=0;i+1<leaf.size();i+=2) cout<<leaf[i]<<' '<<leaf[i+1]<<'\n';
if(leaf.size()%2) cout<<leaf.back()<<' '<<leaf[0]<<'\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... |