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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
vector<vector<int>> g(n);
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v; --u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> cnd;
function<void(int, int)> dfs = [&](int u, int p) {
if (g[u].size() == 1) {
cnd.push_back(u + 1);
}
for (auto v : g[u]) {
if (v ^ p) {
dfs(v, u);
}
}
};
dfs(1, 1);
if (cnd.size() & 1) {
cnd.push_back(cnd[0]);
}
int m = cnd.size() / 2;
cout << m << "\n";
for (int i = 0; i < m; ++i) {
cout << cnd[i] << " " << cnd[i + m] << "\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... |