# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
923294 | Aiperiii | Network (BOI15_net) | C++14 | 539 ms | 48612 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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=5e5+5;
vector <int> g[N];
vector <int> lf;
void dfs(int v,int p){
if(g[v].size()==1)lf.pb(v);
for(auto to : g[v]){
if(to!=p){
dfs(to,v);
}
}
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n;cin>>n;
for(int i=0;i<n-1;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
dfs(1,0);
cout<<(lf.size()+1)/2<<"\n";
for(int i=0;i<(lf.size()+1)/2;i++){
cout<<lf[i]<<" "<<lf[i+lf.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... |