Submission #170903

#TimeUsernameProblemLanguageResultExecution timeMemory
170903nafis_shifatNetwork (BOI15_net)C++14
100 / 100
1460 ms47796 KiB
#include<bits/stdc++.h> #define pii pair<int,int> #define ll long long #define s second using namespace std; const int mxn=5e5+6; vector<int> tree[mxn]; vector<int> lf; int root=1; void dfs(int cur,int prev) { if(tree[cur].size()==1)lf.push_back(cur); for(int i:tree[cur]) { if(i!=prev) { dfs(i,cur); } } } int main() { int n; cin>>n; for(int i=1;i<n;i++) { int u,v; cin>>u>>v; tree[u].push_back(v); tree[v].push_back(u); } dfs(root,-1); int r=lf.size(); cout<<(r+1)/2<<endl; int md=(r+1)/2; for(int i=0;i<md;i++) { if(i+md<r) cout<<lf[i]<<" "<<lf[i+md]<<endl; else cout<<lf[i]<<" "<<lf[r-1]<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...