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 <iostream>
#include <vector>
using namespace std;
const int N = 500005;
vector <int> g[N];
int v[N];
int main()
{
int n, i, nr = 0, a, b;
cin >> n;
for (i = 1; i < n; i++)
{
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for (i = 1; i <= n; i++)
if (g[i].size() == 1)
v[++nr] = i;
if (nr % 2)
v[++nr] = v[1];
cout << nr / 2;
for (i = 1; i <= nr; i += 2)
cout << endl << v[i] << " " << v[i + 1];
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... |