Submission #310014

#TimeUsernameProblemLanguageResultExecution timeMemory
310014nicolaalexandraNetwork (BOI15_net)C++14
0 / 100
9 ms12160 KiB
#include <bits/stdc++.h> #define DIM 500010 using namespace std; vector <int> L[DIM],v; int g[DIM]; int n,i,j,x,y,rad; void dfs (int nod, int tata){ int ok = 0; for (auto vecin : L[nod]) if (vecin != tata){ ok = 1; dfs (vecin,nod); } if (!ok) v.push_back(nod); } int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n; for (i=1;i<n;i++){ cin>>x>>y; L[x].push_back(y); L[y].push_back(x); g[x]++, g[y]++; } for (i=1;i<=n;i++) if (g[i] >= 2){ rad = i; break; } dfs (rad,0); cout<<(v.size()+1)/2<<"\n"; if (v.size() % 2){ cout<<v.back()<<" "<<rad<<"\n"; v.pop_back(); } i = 0, j = v.size()-1; while (i < j){ cout<<v[i]<<" "<<v[j]<<"\n"; i++, j--; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...