Submission #76788

#TimeUsernameProblemLanguageResultExecution timeMemory
76788shoemakerjoNetwork (BOI15_net)C++14
100 / 100
749 ms72480 KiB
#include <bits/stdc++.h> using namespace std; #define maxn 500010 int n; vector<vector<int>> adj(maxn); vector<int> leaves; void dfs(int u, int p) { if (adj[u].size() == 1) leaves.push_back(u); for (int v : adj[u]) { if (v != p) dfs(v, u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int a, b; for (int i = 0; i < n-1; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if (adj[i].size() != 1 || i == n) { dfs(i, -1); break; } } cout << (leaves.size()+1)/2 << endl; for (int i = 0; i + leaves.size()/2 < leaves.size(); i++) { cout << leaves[i] << " " << leaves[i + leaves.size()/2] << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...