# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24512 | Bruteforceman | Network (BOI15_net) | C++11 | 3 ms | 15696 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;
int deg[500010];
deque <int> nodes;
vector <int> g[500010];
void dfs(int x, int par) {
if(deg[x] == 1) {
nodes.push_back(x);
}
for(auto i : g[x]) {
if(i - par) {
dfs(i, x);
}
}
}
int main(int argc, char const *argv[])
{
int n;
scanf("%d", &n);
for(int i = 1; i < n; i++) {
int p, q;
scanf("%d %d", &p, &q);
++deg[p];
++deg[q];
g[p].push_back(q);
g[q].push_back(p);
}
for(int i = 1; i <= n; i++) {
if(deg[i] != 1) {
dfs(i, 0);
break;
}
}
printf("%d\n", (nodes.size() + 1) >> 1);
int good = nodes.front();
while(nodes.size() > 1) {
int p = nodes.front();
int q = nodes.back();
nodes.pop_front();
nodes.pop_back();
printf("%d %d\n", p, q);
}
if(!nodes.empty()) {
printf("%d %d\n", good, nodes.front());
}
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... |