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;
#define lesgooo ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
signed main()
{
lesgooo;
int n, u, v;
cin >> n;
vector<int> adj[n];
for (int i = 1; i < n; i++) cin >> u >> v, adj[--u].push_back(--v), adj[v].push_back(u);
set<int> leaf;
for (int i = 0;i < n; i++) if (adj[i].size() == 1) leaf.insert(i);
cout << (leaf.size()+1)/2 << endl;
int temp = *leaf.begin();
while (leaf.size())
{
cout << *leaf.begin()+1 << " ", leaf.erase(leaf.begin());
if (leaf.size()) cout << *leaf.begin()+1 << endl, leaf.erase(leaf.begin());
else cout << temp+1 << endl;
}
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... |