Submission #1098036

#TimeUsernameProblemLanguageResultExecution timeMemory
1098036AndrijaMNetwork (BOI15_net)C++14
100 / 100
430 ms49740 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn=5e5+10; const int mod=998244353; vector<int>g[maxn]; vector<int>v; void dfs(int node,int par) { if(g[node].size()==1) { v.push_back(node); return ; } for(auto ax:g[node]) { if(ax==par)continue; dfs(ax,node); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ///freopen("lexicografic.in","r",stdin); ///freopen("lexicografic.out","w",stdout); int n; cin>>n; for(int i=0;i<n-1;i++) { int a,b; cin>>a>>b; a--;b--; g[a].push_back(b); g[b].push_back(a); } for(int i=0;i<n;i++) { if(g[i].size()!=1) { dfs(i,-1); break; } } vector<pair<int,int>>ans; int kol=v.size(); kol/=2; for(int i=0;i<kol;i++) { ans.push_back({v[i],v[i+kol]}); } if(v.size()%2==1) { ans.push_back({v[0],v[v.size()-1]}); } cout<<ans.size()<<endl; for(auto ax:ans) { cout<<ax.first+1<<" "<<ax.second+1<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...