# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26108 | bugmenot111 | Network (BOI15_net) | C++14 | 726 ms | 43112 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 <cstdio>
#include <vector>
#define MAXN 500500
std::vector<int> g[MAXN];
int leaves[MAXN], leaves_top;
void dfs(int v, int p) {
if(g[v].size() == 1) leaves[leaves_top++] = v;
for(int c: g[v]) if(c != p) dfs(c, v);
}
int main(void) {
int n;
scanf("%d", &n);
for(int i = 1; i < n; i++) {
int src, dst;
scanf("%d%d", &src, &dst);
src--;
dst--;
g[src].push_back(dst);
g[dst].push_back(src);
}
dfs(0, -1);
int nv = (leaves_top + 1) / 2;
printf("%d\n", nv);
for(int i = 0; i < nv; i++) {
int src = leaves[i];
int dst = leaves[(i + nv) % leaves_top];
src++;
dst++;
printf("%d %d\n", src, dst);
}
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... |