# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24994 | minimario | Network (BOI15_net) | C++14 | 9 ms | 13736 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 MAX = 500000;
vector<int> g[MAX];
vector<int> order;
void dfs(int u, int p) {
for (int i : g[u]) {
if (i == p) { continue; }
dfs(i, u);
}
if (g[u].size() == 1) { order.push_back(u); }
}
int main() {
/*
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
*/
int n; scanf("%d", &n);
for (int i = 0; i < n-1; ++i)
{
int u, v; scanf("%d %d", &u, &v);
u--; v--;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(0, -1);
for (int i = 0; i < order.size(); ++i)
{
order[i]++;
}
printf("%d\n", ((int)order.size()+1)/2);
for (int i = 0; i < ((int)order.size())/2; ++i)
{
printf("%d %d\n", order[i], order[i+(order.size())/2]);
}
if (order.size() % 2 == 1) { printf("%d %d\n", order[0], order[order.back()]); }
}
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... |