Submission #169007

#TimeUsernameProblemLanguageResultExecution timeMemory
169007_qVp_Network (BOI15_net)C++14
100 / 100
559 ms59556 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 + 1) / 2; i++) cout << leaves[i] << " " << leaves[i + len / 2] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...