Submission #169005

#TimeUsernameProblemLanguageResultExecution timeMemory
169005_qVp_Network (BOI15_net)C++14
0 / 100
28 ms23932 KiB
#include <bits/stdc++.h> using namespace std; const int md = 1e6 + 10; vector < int > adj[md]; vector < int > leaves; int n; void dfs(int u, int par) { if (adj[u].size() == 1) leaves.push_back(u); for(auto v : adj[u]) { if (v != par) dfs(v, u); } } int main() { //freopen("test.in", "r", stdin); ios_base::sync_with_stdio(0); cin >> n; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1, -1); int len = leaves.size(); cout << (len + 1) / 2 << '\n'; for(int i = 0; i < len / 2; i++) cout << leaves[i] << " " << leaves[len - i - 1] << '\n'; if (len & 1) cout << leaves[len / 2] << " " << leaves[len / 2 + 1]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...