# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
876008 | vjudge1 | Network (BOI15_net) | C++17 | 1 ms | 348 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 main(){
int n;
cin>>n;
vector<int> links[n+1];
for(int i=0; i<n-1; i++){
int a,b;
cin>>a>>b;
links[a].push_back(b);
links[b].push_back(a);
}
int last=0;
int total=0;
vector<pair<int,int>> ans;
for(int i=1; i<=n; i++){
if(links[i].size()==1){
if(last==0){
last=i;
}
else{
total++;
ans.push_back({last,i});
last=0;
}
}
}
if(last!=0){
total++;
if(last==1){
ans.push_back({last,2});
}
else{
ans.push_back({last,1});
}
}
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... |