Submission #987617

#TimeUsernameProblemLanguageResultExecution timeMemory
987617nihonNetwork (BOI15_net)C++14
0 / 100
4 ms14940 KiB
#include <bits/stdc++.h> #define N 500005 using namespace std; int n,m,i,j,a,b,t,x,ok,l[N],f[N]; bool r[N]; vector<int> v[N]; vector<pair<int,int>> sol; int main() { cin>>n; for(i=1;i<n;++i) { cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } for(i=2;i<=n;++i) { if(v[i].size()==1) { ++t; f[t]=i; l[i]=t; } } m=v[1].size(); for(i=0;i<m;++i) { x=v[1][i]; r[x]=1; } for(x=1;x<=n;++x) { if(r[x]) continue; if(l[x]) { swap(f[t],f[l[x]]); ok=1; break; } } for(i=2;i<=t;i+=2) { sol.push_back({f[i-1],f[i]}); } if(ok) { sol.push_back({1,f[t]}); } m=sol.size(); cout<<m<<'\n'; for(i=0;i<m;++i) { cout<<sol[i].first<<' '<<sol[i].second<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...