# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
76787 | 2018-09-18T03:44:00 Z | shoemakerjo | Network (BOI15_net) | C++14 | 13 ms | 12148 KB |
#include <bits/stdc++.h> using namespace std; #define maxn 500010 int n; vector<vector<int>> adj(maxn); vector<int> leaves; void dfs(int u, int p) { if (adj[u].size() == 1) leaves.push_back(u); for (int v : adj[u]) { if (v != p) dfs(v, u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int a, b; for (int i = 0; i < n-1; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if (adj[i].size() != 1 || i == n) { dfs(i, -1); break; } } cout << (leaves.size()+1)/2 << endl; for (int i = 0; i < leaves.size()/2; i++) { cout << leaves[i] << " " << leaves[leaves.size()-i-1] << endl; } if (leaves.size() % 2) { cout << leaves[leaves.size()/2] << " " << leaves[0] << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12024 KB | Output is correct |
2 | Incorrect | 13 ms | 12148 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12024 KB | Output is correct |
2 | Incorrect | 13 ms | 12148 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12024 KB | Output is correct |
2 | Incorrect | 13 ms | 12148 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |