# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
771885 | 2023-07-03T11:15:40 Z | Blagoj | Connecting Supertrees (IOI20_supertrees) | C++17 | 161 ms | 28176 KB |
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; int leader[1005], ranking[1005]; int Find(int n) { if (leader[n] != n) leader[n] = Find(leader[n]); return leader[n]; } void Union(int x, int y) { x = Find(x), y = Find(y); if (ranking[x] > ranking[y]) swap(x, y); ranking[y] += ranking[x]; leader[x] = y; } vector<int> g[1005]; bool visited[1005]; vector<int> components; void dfs(int n) { visited[n] = 1; components.push_back(n); for (auto x : g[n]) { if (visited[x]) continue; dfs(x); } } int construct(vector<vector<int>> p) { int n = p.size(); for (int i = 0; i <= n; i++) { leader[i] = i; ranking[i] = 1; } vector<vector<int>> answer(n, vector<int>(n)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j] == 3) return 0; if (p[i][j] == 1) Union(i, j); } } for (int i = 0; i < n; i++) if (Find(i) != i) answer[Find(i)][i] = answer[i][Find(i)] = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j] == 0 && Find(i) == Find(j)) return 0; if (p[i][j] == 2 && Find(i) == i && Find(j) == j) { g[i].push_back(j); g[j].push_back(i); } } } for (int i = 0; i < n; i++) { if (Find(i) != i || visited[i]) continue; dfs(i); if (components.size() == 2) return 0; for (auto x : components) { for (auto y : components) if (x != y && p[x][y] != 2) return 0; } for (int j = 0; j < components.size() - 1; j++) { answer[components[j]][components[j + 1]] = answer[components[j + 1]][components[j]] = 1; } if (components.size() != 1) answer[components[0]][components[components.size() - 1]] = answer[components.size() - 1][components[0]] = 1; components.clear(); } build(answer); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1212 KB | Output is correct |
7 | Correct | 154 ms | 24092 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1212 KB | Output is correct |
7 | Correct | 154 ms | 24092 KB | Output is correct |
8 | Correct | 0 ms | 328 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 6 ms | 1268 KB | Output is correct |
13 | Correct | 152 ms | 24020 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 324 KB | Output is correct |
16 | Correct | 3 ms | 820 KB | Output is correct |
17 | Correct | 87 ms | 14092 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 38 ms | 6220 KB | Output is correct |
21 | Correct | 151 ms | 23964 KB | Output is correct |
22 | Correct | 161 ms | 23948 KB | Output is correct |
23 | Correct | 158 ms | 23928 KB | Output is correct |
24 | Correct | 153 ms | 24012 KB | Output is correct |
25 | Correct | 64 ms | 14096 KB | Output is correct |
26 | Correct | 63 ms | 14104 KB | Output is correct |
27 | Correct | 154 ms | 23952 KB | Output is correct |
28 | Correct | 152 ms | 23948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 0 ms | 328 KB | Output is correct |
6 | Correct | 1 ms | 324 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 7 ms | 1236 KB | Output is correct |
9 | Correct | 153 ms | 23952 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1492 KB | Output is correct |
13 | Correct | 157 ms | 28176 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 976 KB | Output is correct |
17 | Correct | 75 ms | 16912 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Incorrect | 38 ms | 6292 KB | b is not symmetric: b[0][26] (0) != b[26][0] (1) |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 324 KB | Output is correct |
4 | Correct | 38 ms | 6236 KB | Output is correct |
5 | Correct | 152 ms | 23964 KB | Output is correct |
6 | Correct | 154 ms | 23980 KB | Output is correct |
7 | Correct | 156 ms | 23952 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Incorrect | 38 ms | 6288 KB | b is not symmetric: b[0][26] (0) != b[26][0] (1) |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1212 KB | Output is correct |
7 | Correct | 154 ms | 24092 KB | Output is correct |
8 | Correct | 0 ms | 328 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 6 ms | 1268 KB | Output is correct |
13 | Correct | 152 ms | 24020 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 324 KB | Output is correct |
16 | Correct | 3 ms | 820 KB | Output is correct |
17 | Correct | 87 ms | 14092 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 38 ms | 6220 KB | Output is correct |
21 | Correct | 151 ms | 23964 KB | Output is correct |
22 | Correct | 161 ms | 23948 KB | Output is correct |
23 | Correct | 158 ms | 23928 KB | Output is correct |
24 | Correct | 153 ms | 24012 KB | Output is correct |
25 | Correct | 64 ms | 14096 KB | Output is correct |
26 | Correct | 63 ms | 14104 KB | Output is correct |
27 | Correct | 154 ms | 23952 KB | Output is correct |
28 | Correct | 152 ms | 23948 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 328 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 328 KB | Output is correct |
33 | Correct | 0 ms | 328 KB | Output is correct |
34 | Correct | 1 ms | 324 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 7 ms | 1236 KB | Output is correct |
37 | Correct | 153 ms | 23952 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 7 ms | 1492 KB | Output is correct |
41 | Correct | 157 ms | 28176 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 0 ms | 212 KB | Output is correct |
44 | Correct | 4 ms | 976 KB | Output is correct |
45 | Correct | 75 ms | 16912 KB | Output is correct |
46 | Correct | 0 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Incorrect | 38 ms | 6292 KB | b is not symmetric: b[0][26] (0) != b[26][0] (1) |
50 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1212 KB | Output is correct |
7 | Correct | 154 ms | 24092 KB | Output is correct |
8 | Correct | 0 ms | 328 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 6 ms | 1268 KB | Output is correct |
13 | Correct | 152 ms | 24020 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 324 KB | Output is correct |
16 | Correct | 3 ms | 820 KB | Output is correct |
17 | Correct | 87 ms | 14092 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 38 ms | 6220 KB | Output is correct |
21 | Correct | 151 ms | 23964 KB | Output is correct |
22 | Correct | 161 ms | 23948 KB | Output is correct |
23 | Correct | 158 ms | 23928 KB | Output is correct |
24 | Correct | 153 ms | 24012 KB | Output is correct |
25 | Correct | 64 ms | 14096 KB | Output is correct |
26 | Correct | 63 ms | 14104 KB | Output is correct |
27 | Correct | 154 ms | 23952 KB | Output is correct |
28 | Correct | 152 ms | 23948 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 328 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 328 KB | Output is correct |
33 | Correct | 0 ms | 328 KB | Output is correct |
34 | Correct | 1 ms | 324 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 7 ms | 1236 KB | Output is correct |
37 | Correct | 153 ms | 23952 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 7 ms | 1492 KB | Output is correct |
41 | Correct | 157 ms | 28176 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 0 ms | 212 KB | Output is correct |
44 | Correct | 4 ms | 976 KB | Output is correct |
45 | Correct | 75 ms | 16912 KB | Output is correct |
46 | Correct | 0 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Incorrect | 38 ms | 6292 KB | b is not symmetric: b[0][26] (0) != b[26][0] (1) |
50 | Halted | 0 ms | 0 KB | - |