# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
609294 | sword060 | Network (BOI15_net) | C++17 | 7 ms | 11988 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;
int x;
vector<int>v[500005];
vector<pair<int,int>>ans;
vector<int> dfs(int i,int p=-1){
vector<int>ret;
if(v[i].size()==1)ret.push_back(i);
for(auto j:v[i]){
if(j==p)continue;
vector<int>lol=dfs(j,i);
for(auto k:lol)ret.push_back(k);
}
if(i==1){
for(int j=0;j<ret.size()/2;j++)
ans.push_back({ret[j],ret[ret.size()-j-1]});
if((int)ret.size()%2)ans.push_back({ret[ret.size()/2],ret.back()});
}
return ret;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>x;
for(int i=1;i<=x-1;i++){
int l,r;cin>>l>>r;
v[l].push_back(r);
v[r].push_back(l);
}
dfs(1);
cout<<ans.size()<<"\n";
for(auto [l,r]:ans)cout<<l<<" "<<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... |