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;
void testCase() {
int n;
cin >> n;
vector<int> d(n + 1);
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
d[u] += 1;
d[v] += 1;
}
int node = -1;
vector<int> v;
for (int i = 1; i <= n; ++i) {
if (d[i] == 1) {
v.emplace_back(i);
} else {
node = i;
}
}
if ((int)v.size() % 2 == 1) {
v.emplace_back(node);
}
cout << v.size() / 2 << '\n';
for (int i = 0; i < (int)v.size(); i += 2) {
cout << v[i] << ' ' << v[i + 1] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
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... |