# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
69457 | 2018-08-21T01:06:31 Z | kingpig9 | Network (BOI15_net) | C++11 | 15 ms | 12136 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define debug(...) fprintf(stderr, __VA_ARGS__) //#define debug(...) #define all(v) (v).begin(), (v).end() #define fillchar(a, s) memset((a), (s), sizeof(a)) #define fi first #define se second int N; vector<int> adj[500010]; vector<int> leaves; void dfs (int x, int p) { if (adj[x].size() == 1) { leaves.push_back(x); } for (int y : adj[x]) { if (y != p) { dfs(y, x); } } } int main() { scanf("%d", &N); for (int i = 1; i < N; i++) { int x, y; scanf("%d %d", &x, &y); adj[x].push_back(y); adj[y].push_back(x); } int root = 1; while (adj[root].size() == 1) { root++; } dfs(root, -1); vector<pii> ans; for (int i = 0, j = leaves.size() - 1; i < j; i++, j--) { ans.push_back({leaves[i], leaves[j]}); } if (leaves.size() % 2) { ans.push_back({leaves[leaves.size() / 2], leaves[0]}); } printf("%lu\n", ans.size()); for (pii p : ans) { printf("%d %d\n", p.fi, p.se); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12084 KB | Output is correct |
2 | Incorrect | 15 ms | 12136 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12084 KB | Output is correct |
2 | Incorrect | 15 ms | 12136 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12084 KB | Output is correct |
2 | Incorrect | 15 ms | 12136 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |