# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81555 | arman_ferdous | Network (BOI15_net) | C++17 | 12 ms | 12180 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+10;
int n, d[N];
vector<int> g[N], leaf;
int main() {
scanf("%d", &n);
for(int i = 1; i < n; i++) {
int u, v; scanf("%d %d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
d[u]++, d[v]++;
}
for(int i = 1; i <= n; i++) if(d[i] == 1)
leaf.push_back(i);
random_shuffle(leaf.begin(),leaf.end());
random_shuffle(leaf.begin(),leaf.end());
int sz = leaf.size();
printf("%d\n", (int)ceil(sz/2.));
for(int i = 0; i < sz; i+=2) {
if(i+1 < sz) printf("%d %d\n", leaf[i], leaf[i+1]);
else printf("%d %d\n", leaf[i], leaf[0]);
}
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... |