#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 500005
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
ll n;
vector<ll> adj[MAXN], lvs;
void dfs(ll i, ll p){
if(adj[i].size() == 1) lvs.push_back(i);
for(ll i2 : adj[i]){
if(i2 != p) dfs(i2, i);
}
}
int main(){
cin >> n;
FOR(i, 1, n - 1){
ll x, y;
cin >> x >> y;
adj[x].push_back(y), adj[y].push_back(x);
}
dfs(1, -1);
cout << (lvs.size() + 1) / 2 << endl;
FOR(i, 0, (lvs.size() + 1) / 2 - 1){
cout << lvs[i] << " " << lvs[i + (lvs.size() / 2)] << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |