# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126208 | Vardanyan | Network (BOI15_net) | C++14 | 15 ms | 12152 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;
const int N = 500*1000+5;
vector<int> g[N];
int main(){
ios_base::sync_with_stdio(false);
int n;
cin>>n;
for(int i = 1;i<=n-1;i++){
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
vector<int> lf;
for(int i = 1;i<=n;i++){
if(g[i].size() == 1) lf.push_back(i);
}
random_shuffle(lf.begin(),lf.end());
cout<<(lf.size()+1)/2<<endl;
for(int i = 0;i<lf.size()-1;i+=2){
cout<<lf[i]<< " "<<lf[i+1]<<endl;
}
if(lf.size()%2){
cout<<lf[lf.size()-1]<<" "<<lf[0]<<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... |