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;
vector<int> adj[500005], vec;
void dfs(int u, int p)
{
if (adj[u].size()==1)
vec.push_back(u);
for (int v:adj[u])
if (v!=p)
dfs(v, u);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, sz;
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, 0);
sz=vec.size();
cout << (sz+1)/2 << '\n';
for (int i=0; i<(sz+1)/2; i++)
cout << vec[i] << ' ' << vec[i+sz/2] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |