# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
95936 | 2019-02-04T14:49:53 Z | luciocf | Network (BOI15_net) | C++14 | 10 ms | 12028 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5+10; typedef pair<int, int> pii; int leaf[maxn], tt; vector<int> grafo[maxn]; void dfs(int u, int p) { for (auto v: grafo[u]) { if (v == p) continue; dfs(v, u); } if (grafo[u].size() == 1) leaf[++tt] = u; } int main(void) { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; grafo[u].push_back(v); grafo[v].push_back(u); } int root; for (int i = 1; i <= n; i++) if (grafo[i].size() > 1) root = i; dfs(root, 0); int ans = (tt+1)/2; cout << ans << "\n"; for (int i = 1; i < ans; i++) cout << leaf[i] << " " << leaf[i+ans] << "\n"; if (ans&1) cout << leaf[ans] << " " << leaf[1] << "\n"; else cout << leaf[ans] << " " << leaf[tt] << "\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 12028 KB | Breaking single line is causing network to disconnect. |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 12028 KB | Breaking single line is causing network to disconnect. |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 12028 KB | Breaking single line is causing network to disconnect. |
2 | Halted | 0 ms | 0 KB | - |