# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
109404 | IVIosab | Network (BOI15_net) | C++17 | 766 ms | 47708 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(500005);
vector<int> leafs;
void dfs(int curn,int prev){
if(adj[curn].size()==1){
leafs.push_back(curn);
}
for(int i=0;i<adj[curn].size();i++){
if(adj[curn][i]!=prev){
dfs(adj[curn][i],curn);
}
}
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1,-1);
if(leafs.size()%2==0){
cout<<leafs.size()/2<<"\n";
for(int i=0;i<leafs.size()/2;i++){
cout<<leafs[i]<<" "<<leafs[i+leafs.size()/2]<<"\n";
}
}
else{
cout<<leafs.size()/2+1<<"\n";
for(int i=0;i<leafs.size()/2;i++){
cout<<leafs[i]<<" "<<leafs[i+leafs.size()/2+1]<<"\n";
}
cout<<leafs[leafs.size()/2]<<" 1\n";
}
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... |