Submission #492423

#TimeUsernameProblemLanguageResultExecution timeMemory
492423RainbowbunnyNetwork (BOI15_net)C++17
100 / 100
411 ms51892 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 5; int n; vector <int> Leaves; vector <int> Adj[MAXN]; void DFS(int node, int p = -1) { for(auto x : Adj[node]) { if(x == p) { continue; } DFS(x, node); } if(Adj[node].size() == 1) { Leaves.push_back(node); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(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); int s = Leaves.size(); cout << (int)(s + 1) / 2 << '\n'; for(int i = 0; i < (s + 1) / 2; i++) { cout << Leaves[i] << ' ' << Leaves[(i + (s + 1) / 2) % s] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...