# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151239 | cfalas | Network (BOI15_net) | C++14 | 1455 ms | 53260 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;
vector<vector<int> > adj;
vector<int> ans;
void dfs(int s, int p=-1){
if(adj[s].size()==1){
ans.push_back(s);
}
for(auto v : adj[s] ){
if(v!=p) dfs(v, s);
}
}
int main(){
int n;
adj.assign(1000000, vector<int>());
cin>>n;
for(int i=0;i<n-1;i++){
int b, c;
cin>>b>>c;
adj[b].push_back(c);
adj[c].push_back(b);
}
dfs(1);
cout<<(ans.size()+1)/2<<endl;
for(int i=0;i<(ans.size()+1)/2;i++){
cout<<ans[i]<<" "<<ans[(i+(ans.size()+1)/2)%ans.size()]<<endl;
}
}
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... |