# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
876013 | vjudge1 | Network (BOI15_net) | C++17 | 651 ms | 41908 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;
bool seen[500005]={false};
vector<int> links[500005];
vector<int> roots;
int last=-1;
void dfs(int at){
if(seen[at]){
return;
}
seen[at]=true;
if(links[at].size()==1){
roots.push_back(at);
}
for(int to:links[at]){
if(!seen[to]) dfs(to);
}
}
int main(){
int n;
cin>>n;
for(int i=0; i<n-1; i++){
int a,b;
cin>>a>>b;
links[a].push_back(b);
links[b].push_back(a);
}
dfs(1);
int total=roots.size()/2;
vector<pair<int,int>> ans;
for(int i=0; i<total; i++){
ans.push_back({roots[i],roots[i+total]});
}
if(roots.size()%2==1){
ans.push_back({roots[0],roots[roots.size()-1]});
total++;
}
cout<<total<<endl;
for(int i=0; i<ans.size(); i++){
cout<<ans[i].first<<' '<<ans[i].second<<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... |