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;
const int MAX_N = 500005;
vector<int> G[MAX_N];
vector<int> ord;
void DFS(int u, int p) {
for (int v : G[u]) {
if (v != p) {
DFS(v, u);
}
}
if (G[u].size() == 1) {
ord.push_back(u);
}
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N - 1; i++) {
int u, v;
cin >> u >> v;
u--, v--;
G[u].push_back(v);
G[v].push_back(u);
}
DFS(0, -1);
int L = (int)ord.size();
cout << (L + 1) / 2 << "\n";
for (int i = 0; i < (L + 1) / 2; i++) {
cout << 1 + ord[i] << " " << 1 + ord[i + L / 2] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |