# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24512 | 2017-06-09T14:45:26 Z | Bruteforceman | Network (BOI15_net) | C++11 | 3 ms | 15696 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 15696 KB | Output is correct |
2 | Incorrect | 3 ms | 15696 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 15696 KB | Output is correct |
2 | Incorrect | 3 ms | 15696 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 15696 KB | Output is correct |
2 | Incorrect | 3 ms | 15696 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |