# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335635 | Joshc | Network (BOI15_net) | C++11 | 542 ms | 52328 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>
using namespace std;
vector<int> edges[500001], l;
void dfs(int v, int p) {
if (edges[v].size() == 1) l.push_back(v);
for (int u : edges[v]) {
if (u != p) dfs(u, v);
}
}
int main() {
int n, a, b;
scanf("%d", &n);
for (int i=1; i<n; i++) {
scanf("%d%d", &a, &b);
edges[a].push_back(b);
edges[b].push_back(a);
}
dfs(1, 0);
int s = (l.size()+1)>>1;
printf("%d\n", s);
for (int i=0; i<s; i++) printf("%d %d\n", l[i], l[(i+s)%l.size()]);
}
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... |