# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239825 | kshitij_sodani | Network (BOI15_net) | C++17 | 12 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;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n;
vector<int> adj[500001];
vector<int> kk;
void dfs(int no,int par=-1){
for(auto j:adj[no]){
if(j!=par){
dfs(j,no);
}
}
if(adj[no].size()==1){
kk.pb(no);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(int i=0;i<n-1;i++){
int aa,bb;
cin>>aa>>bb;
adj[aa-1].pb(bb-1);
adj[bb-1].pb(aa-1);
}
int r=0;
for(int i=0;i<n;i++){
if(adj[i].size()>1){
r=i;
}
}
dfs(r);
cout<<((kk.size()+1)/2)<<endl;
for(int i=0;i<kk.size()/2;i++){
cout<<kk[i]+1<<" "<<kk[kk.size()-i-1]+1<<endl;
}
if(kk.size()%2==1){
cout<<kk[kk.size()/2]+1<<" "<<r<<endl;
}
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... |