# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
605838 | 2022-07-26T03:22:16 Z | buidangnguyen05 | Network (BOI15_net) | C++14 | 1982 ms | 86856 KB |
//source: https://oj.uz/problem/view/BOI15_net #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e5 + 10; vector<int> adj[N]; vector<pair<int, int>> ans; vector<int> dfs(int x, int par) { if (adj[x].size() == 1) return vector<int>(1, x); vector<int> cur; for (int i : adj[x]) if (i != par) { vector<int> v = dfs(i, x); if (cur.size() < v.size()) swap(v, cur); while (cur.size() + v.size() > 2 && v.size()) { int p = cur.back(); cur.pop_back(); int q = v.back(); v.pop_back(); cerr << x << " " << p << " " << q << "\n"; ans.emplace_back(p, q); } for (int j : v) cur.push_back(j); } return cur; } signed main() { cin.tie(0)->sync_with_stdio(0); if (fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } int n; cin >> n; for (int i = 1; i < n; ++i) { int x, y; cin >> x >> y; adj[x].push_back(y); adj[y].push_back(x); //ans.emplace_back(x, y); } int root = 0, save1 = 0, save2 = 0; for (int i = 1; i <= n; ++i) { if (adj[i].size() > 1 && !root) root = i; else if (adj[i].size() == 1 && !save1) save1 = i; else if (adj[i].size() == 1 && !save2) save2 = i; } //cerr << root << "\n"; vector<int> rem = dfs(root, 0); if (rem.size() > 1) { int u = rem.back(); rem.pop_back(); int v = rem.back(); rem.pop_back(); ans.emplace_back(u, v); } if (rem.size()) ans.emplace_back(rem.back(), (save1 == rem.back() ? save2 : save1)); cout << ans.size() << "\n"; for (pair<int, int> i : ans) cout << i.first << " " << i.second << "\n"; cout << endl; //system("graph_.exe"); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Correct | 6 ms | 11988 KB | Output is correct |
3 | Correct | 6 ms | 11988 KB | Output is correct |
4 | Correct | 7 ms | 11988 KB | Output is correct |
5 | Correct | 6 ms | 11988 KB | Output is correct |
6 | Correct | 7 ms | 12044 KB | Output is correct |
7 | Correct | 6 ms | 11988 KB | Output is correct |
8 | Correct | 6 ms | 11988 KB | Output is correct |
9 | Correct | 6 ms | 11988 KB | Output is correct |
10 | Correct | 8 ms | 11988 KB | Output is correct |
11 | Correct | 6 ms | 11988 KB | Output is correct |
12 | Correct | 6 ms | 11988 KB | Output is correct |
13 | Correct | 6 ms | 11988 KB | Output is correct |
14 | Correct | 6 ms | 11988 KB | Output is correct |
15 | Correct | 6 ms | 11988 KB | Output is correct |
16 | Correct | 6 ms | 11988 KB | Output is correct |
17 | Correct | 6 ms | 11988 KB | Output is correct |
18 | Correct | 6 ms | 11988 KB | Output is correct |
19 | Correct | 6 ms | 11988 KB | Output is correct |
20 | Correct | 5 ms | 11988 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Correct | 6 ms | 11988 KB | Output is correct |
3 | Correct | 6 ms | 11988 KB | Output is correct |
4 | Correct | 7 ms | 11988 KB | Output is correct |
5 | Correct | 6 ms | 11988 KB | Output is correct |
6 | Correct | 7 ms | 12044 KB | Output is correct |
7 | Correct | 6 ms | 11988 KB | Output is correct |
8 | Correct | 6 ms | 11988 KB | Output is correct |
9 | Correct | 6 ms | 11988 KB | Output is correct |
10 | Correct | 8 ms | 11988 KB | Output is correct |
11 | Correct | 6 ms | 11988 KB | Output is correct |
12 | Correct | 6 ms | 11988 KB | Output is correct |
13 | Correct | 6 ms | 11988 KB | Output is correct |
14 | Correct | 6 ms | 11988 KB | Output is correct |
15 | Correct | 6 ms | 11988 KB | Output is correct |
16 | Correct | 6 ms | 11988 KB | Output is correct |
17 | Correct | 6 ms | 11988 KB | Output is correct |
18 | Correct | 6 ms | 11988 KB | Output is correct |
19 | Correct | 6 ms | 11988 KB | Output is correct |
20 | Correct | 5 ms | 11988 KB | Output is correct |
21 | Correct | 6 ms | 11988 KB | Output is correct |
22 | Correct | 16 ms | 12152 KB | Output is correct |
23 | Correct | 16 ms | 12176 KB | Output is correct |
24 | Correct | 15 ms | 12116 KB | Output is correct |
25 | Correct | 11 ms | 12156 KB | Output is correct |
26 | Correct | 10 ms | 12144 KB | Output is correct |
27 | Correct | 12 ms | 12136 KB | Output is correct |
28 | Correct | 11 ms | 12044 KB | Output is correct |
29 | Correct | 10 ms | 12116 KB | Output is correct |
30 | Correct | 6 ms | 11988 KB | Output is correct |
31 | Correct | 11 ms | 12116 KB | Output is correct |
32 | Correct | 6 ms | 11988 KB | Output is correct |
33 | Correct | 6 ms | 11988 KB | Output is correct |
34 | Correct | 6 ms | 12060 KB | Output is correct |
35 | Correct | 6 ms | 11988 KB | Output is correct |
36 | Correct | 7 ms | 11988 KB | Output is correct |
37 | Correct | 8 ms | 12068 KB | Output is correct |
38 | Correct | 8 ms | 12244 KB | Output is correct |
39 | Correct | 7 ms | 11988 KB | Output is correct |
40 | Correct | 7 ms | 12064 KB | Output is correct |
41 | Correct | 6 ms | 12068 KB | Output is correct |
42 | Correct | 8 ms | 11988 KB | Output is correct |
43 | Correct | 11 ms | 12072 KB | Output is correct |
44 | Correct | 7 ms | 11988 KB | Output is correct |
45 | Correct | 7 ms | 11980 KB | Output is correct |
46 | Correct | 10 ms | 11988 KB | Output is correct |
47 | Correct | 7 ms | 11988 KB | Output is correct |
48 | Correct | 7 ms | 12064 KB | Output is correct |
49 | Correct | 11 ms | 12076 KB | Output is correct |
50 | Correct | 7 ms | 12060 KB | Output is correct |
51 | Correct | 6 ms | 11988 KB | Output is correct |
52 | Correct | 6 ms | 12116 KB | Output is correct |
53 | Correct | 7 ms | 12116 KB | Output is correct |
54 | Correct | 6 ms | 11988 KB | Output is correct |
55 | Correct | 7 ms | 11988 KB | Output is correct |
56 | Correct | 6 ms | 12064 KB | Output is correct |
57 | Correct | 9 ms | 11988 KB | Output is correct |
58 | Correct | 15 ms | 12168 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Correct | 6 ms | 11988 KB | Output is correct |
3 | Correct | 6 ms | 11988 KB | Output is correct |
4 | Correct | 7 ms | 11988 KB | Output is correct |
5 | Correct | 6 ms | 11988 KB | Output is correct |
6 | Correct | 7 ms | 12044 KB | Output is correct |
7 | Correct | 6 ms | 11988 KB | Output is correct |
8 | Correct | 6 ms | 11988 KB | Output is correct |
9 | Correct | 6 ms | 11988 KB | Output is correct |
10 | Correct | 8 ms | 11988 KB | Output is correct |
11 | Correct | 6 ms | 11988 KB | Output is correct |
12 | Correct | 6 ms | 11988 KB | Output is correct |
13 | Correct | 6 ms | 11988 KB | Output is correct |
14 | Correct | 6 ms | 11988 KB | Output is correct |
15 | Correct | 6 ms | 11988 KB | Output is correct |
16 | Correct | 6 ms | 11988 KB | Output is correct |
17 | Correct | 6 ms | 11988 KB | Output is correct |
18 | Correct | 6 ms | 11988 KB | Output is correct |
19 | Correct | 6 ms | 11988 KB | Output is correct |
20 | Correct | 5 ms | 11988 KB | Output is correct |
21 | Correct | 6 ms | 11988 KB | Output is correct |
22 | Correct | 16 ms | 12152 KB | Output is correct |
23 | Correct | 16 ms | 12176 KB | Output is correct |
24 | Correct | 15 ms | 12116 KB | Output is correct |
25 | Correct | 11 ms | 12156 KB | Output is correct |
26 | Correct | 10 ms | 12144 KB | Output is correct |
27 | Correct | 12 ms | 12136 KB | Output is correct |
28 | Correct | 11 ms | 12044 KB | Output is correct |
29 | Correct | 10 ms | 12116 KB | Output is correct |
30 | Correct | 6 ms | 11988 KB | Output is correct |
31 | Correct | 11 ms | 12116 KB | Output is correct |
32 | Correct | 6 ms | 11988 KB | Output is correct |
33 | Correct | 6 ms | 11988 KB | Output is correct |
34 | Correct | 6 ms | 12060 KB | Output is correct |
35 | Correct | 6 ms | 11988 KB | Output is correct |
36 | Correct | 7 ms | 11988 KB | Output is correct |
37 | Correct | 8 ms | 12068 KB | Output is correct |
38 | Correct | 8 ms | 12244 KB | Output is correct |
39 | Correct | 7 ms | 11988 KB | Output is correct |
40 | Correct | 7 ms | 12064 KB | Output is correct |
41 | Correct | 6 ms | 12068 KB | Output is correct |
42 | Correct | 8 ms | 11988 KB | Output is correct |
43 | Correct | 11 ms | 12072 KB | Output is correct |
44 | Correct | 7 ms | 11988 KB | Output is correct |
45 | Correct | 7 ms | 11980 KB | Output is correct |
46 | Correct | 10 ms | 11988 KB | Output is correct |
47 | Correct | 7 ms | 11988 KB | Output is correct |
48 | Correct | 7 ms | 12064 KB | Output is correct |
49 | Correct | 11 ms | 12076 KB | Output is correct |
50 | Correct | 7 ms | 12060 KB | Output is correct |
51 | Correct | 6 ms | 11988 KB | Output is correct |
52 | Correct | 6 ms | 12116 KB | Output is correct |
53 | Correct | 7 ms | 12116 KB | Output is correct |
54 | Correct | 6 ms | 11988 KB | Output is correct |
55 | Correct | 7 ms | 11988 KB | Output is correct |
56 | Correct | 6 ms | 12064 KB | Output is correct |
57 | Correct | 9 ms | 11988 KB | Output is correct |
58 | Correct | 15 ms | 12168 KB | Output is correct |
59 | Correct | 1347 ms | 39276 KB | Output is correct |
60 | Correct | 1588 ms | 42180 KB | Output is correct |
61 | Correct | 7 ms | 11988 KB | Output is correct |
62 | Correct | 6 ms | 11988 KB | Output is correct |
63 | Correct | 1313 ms | 36620 KB | Output is correct |
64 | Correct | 8 ms | 13096 KB | Output is correct |
65 | Correct | 21 ms | 16516 KB | Output is correct |
66 | Correct | 120 ms | 51848 KB | Output is correct |
67 | Correct | 431 ms | 84588 KB | Output is correct |
68 | Correct | 564 ms | 86856 KB | Output is correct |
69 | Correct | 63 ms | 13000 KB | Output is correct |
70 | Correct | 595 ms | 22736 KB | Output is correct |
71 | Correct | 1970 ms | 47096 KB | Output is correct |
72 | Correct | 1860 ms | 45208 KB | Output is correct |
73 | Correct | 317 ms | 19760 KB | Output is correct |
74 | Correct | 1283 ms | 40460 KB | Output is correct |
75 | Correct | 229 ms | 15724 KB | Output is correct |
76 | Correct | 1958 ms | 46580 KB | Output is correct |
77 | Correct | 1982 ms | 46592 KB | Output is correct |
78 | Incorrect | 79 ms | 18488 KB | Breaking single line is causing network to disconnect. |
79 | Halted | 0 ms | 0 KB | - |