# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79560 | FutymyClone | Network (BOI15_net) | C++14 | 663 ms | 41528 KiB |
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 N = 5e5 + 5;
int n;
vector <int> vec, g[N];
void dfs (int u, int p) {
bool leaf = true;
for (auto v: g[u]) {
if (v == p) continue;
leaf = false;
dfs(v, u);
}
if (leaf) vec.push_back(u);
}
int main(){
scanf("%d", &n);
for (int i = 1; i <= n - 1; i++) {
int u, v; scanf("%d %d", &u, &v);
g[u].push_back(v); g[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
if (g[i].size() > 1) {
dfs(i, i);
break;
}
}
printf("%d\n", ((int)vec.size() + 1) / 2);
for (int i = 0; i < ((int)vec.size() + 1) / 2; i++) printf("%d %d\n", vec[i], vec[i + vec.size() / 2]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |