Submission #311447

#TimeUsernameProblemLanguageResultExecution timeMemory
311447sofapudenNetwork (BOI15_net)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>> v; vector<int> o; vector<int> lea; void dfs(int x, int p){ for(int y : v[x]){ if(y == p)continue; dfs(y,x); } o.push_back(x); } int main(){ int n; cin >> n; v.resize(n); for(int i = 0; i < n-1; ++i){ int a, b; cin >> a >> b; a--, b--; v[a].push_back(b); v[b].push_back(a); } dfs(0,0); for(int x : o){ if(v[x].size() == 1)lea.push_back(x); } int ln = lea.size(); bool ok = 0; cout << (ln+1)/2 << "\n"; if(lea[ln-1] == 0){ lea.pop_back(); ln--; cout << 1 << " " << lea[ln/2]+1 << "\n"; ok = 1; } for(int i = 0; i < ln/2; ++i){ cout << lea[i]+1 << " " << lea[ln-1-i]+1 << "\n"; } if((ln&1) && !ok){ cout << lea[0]+1 << " " << lea[ln/2]+1 << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...