This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |