Submission #499900

#TimeUsernameProblemLanguageResultExecution timeMemory
499900SirCovidThe19thNetwork (BOI15_net)C++17
100 / 100
642 ms47716 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int> adj[500005], leaf; void dfs(int cur, int p){ if (adj[cur].size() == 1) leaf.push_back(cur); for (int nxt : adj[cur]) if (nxt != p) dfs(nxt, cur); } int main(){ cin >> n; for (int i = 1; i < n; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } dfs(1, 0); int sz = leaf.size(); cout<<(sz + 1) / 2<<"\n"; for (int i = 0; i + sz / 2 < sz; i++) cout<<leaf[i]<<" "<<leaf[i + sz / 2]<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...