# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798940 | 2023-07-31T07:47:15 Z | QwertyPi | Connecting Supertrees (IOI20_supertrees) | C++14 | 182 ms | 24232 KB |
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; struct DSU{ int dsu[1001]; void init(int n){ for(int i = 0; i < n; i++){ dsu[i] = i; } } int f(int x){ return x == dsu[x] ? x : dsu[x] = f(dsu[x]); } void g(int x, int y){ x = f(x), y = f(y); dsu[x] = y; } } dsu0, dsu1; int construct(std::vector<std::vector<int>> p) { int n = p.size(); dsu0.init(n), dsu1.init(n); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[i][j] == 3) return false; } } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[i][j] >= 1) dsu0.g(i, j); if(p[i][j] == 1) dsu1.g(i, j); } } std::vector<std::vector<int>> answer; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); answer.push_back(row); } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[i][j] == 0 && dsu0.f(i) == dsu0.f(j)){ return false; } if(p[i][j] == 2 && dsu1.f(i) == dsu1.f(j)){ return false; } } } map<int, vector<int>> p1, p2; for(int i = 0; i < n; i++){ p1[dsu1.f(i)].push_back(i); } for(auto [i, v] : p1){ for(int j = 1; j < v.size(); j++){ answer[v[0]][v[j]] = answer[v[j]][v[0]] = 1; } p2[dsu0.f(v[0])].push_back(v[0]); } for(auto [i, v] : p2){ if(v.size() == 1) continue; if(v.size() == 2) return false; for(int j = 1; j < v.size(); j++){ answer[v[j - 1]][v[j]] = answer[v[j]][v[j - 1]] = 1; } answer[v[0]][v[v.size() - 1]] = answer[v[v.size() - 1]][v[0]] = 1; } build(answer); return true; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 300 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1212 KB | Output is correct |
7 | Correct | 167 ms | 23984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 300 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1212 KB | Output is correct |
7 | Correct | 167 ms | 23984 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1236 KB | Output is correct |
13 | Correct | 157 ms | 24232 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 304 KB | Output is correct |
16 | Correct | 4 ms | 852 KB | Output is correct |
17 | Correct | 81 ms | 14072 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 40 ms | 6260 KB | Output is correct |
21 | Correct | 159 ms | 23988 KB | Output is correct |
22 | Correct | 158 ms | 24056 KB | Output is correct |
23 | Correct | 160 ms | 24012 KB | Output is correct |
24 | Correct | 161 ms | 24188 KB | Output is correct |
25 | Correct | 71 ms | 14084 KB | Output is correct |
26 | Correct | 70 ms | 14084 KB | Output is correct |
27 | Correct | 160 ms | 23924 KB | Output is correct |
28 | Correct | 158 ms | 24192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 7 ms | 1208 KB | Output is correct |
9 | Correct | 158 ms | 24124 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 | 1212 KB | Output is correct |
13 | Correct | 166 ms | 24052 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 | 852 KB | Output is correct |
17 | Correct | 92 ms | 14068 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 39 ms | 6256 KB | Output is correct |
22 | Correct | 172 ms | 24052 KB | Output is correct |
23 | Correct | 157 ms | 24112 KB | Output is correct |
24 | Correct | 162 ms | 24052 KB | Output is correct |
25 | Correct | 72 ms | 14212 KB | Output is correct |
26 | Correct | 87 ms | 14088 KB | Output is correct |
27 | Correct | 161 ms | 24120 KB | Output is correct |
28 | Correct | 171 ms | 24112 KB | Output is correct |
29 | Correct | 73 ms | 14212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 40 ms | 6244 KB | Output is correct |
5 | Correct | 176 ms | 24016 KB | Output is correct |
6 | Correct | 182 ms | 24056 KB | Output is correct |
7 | Correct | 161 ms | 23960 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 45 ms | 6308 KB | Output is correct |
10 | Correct | 161 ms | 24124 KB | Output is correct |
11 | Correct | 158 ms | 24148 KB | Output is correct |
12 | Correct | 167 ms | 24160 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 40 ms | 6220 KB | Output is correct |
17 | Correct | 171 ms | 24056 KB | Output is correct |
18 | Correct | 168 ms | 24060 KB | Output is correct |
19 | Correct | 162 ms | 24072 KB | Output is correct |
20 | Correct | 162 ms | 24180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 300 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1212 KB | Output is correct |
7 | Correct | 167 ms | 23984 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1236 KB | Output is correct |
13 | Correct | 157 ms | 24232 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 304 KB | Output is correct |
16 | Correct | 4 ms | 852 KB | Output is correct |
17 | Correct | 81 ms | 14072 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 40 ms | 6260 KB | Output is correct |
21 | Correct | 159 ms | 23988 KB | Output is correct |
22 | Correct | 158 ms | 24056 KB | Output is correct |
23 | Correct | 160 ms | 24012 KB | Output is correct |
24 | Correct | 161 ms | 24188 KB | Output is correct |
25 | Correct | 71 ms | 14084 KB | Output is correct |
26 | Correct | 70 ms | 14084 KB | Output is correct |
27 | Correct | 160 ms | 23924 KB | Output is correct |
28 | Correct | 158 ms | 24192 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 304 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 7 ms | 1208 KB | Output is correct |
37 | Correct | 158 ms | 24124 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 | 1212 KB | Output is correct |
41 | Correct | 166 ms | 24052 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 | 852 KB | Output is correct |
45 | Correct | 92 ms | 14068 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 39 ms | 6256 KB | Output is correct |
50 | Correct | 172 ms | 24052 KB | Output is correct |
51 | Correct | 157 ms | 24112 KB | Output is correct |
52 | Correct | 162 ms | 24052 KB | Output is correct |
53 | Correct | 72 ms | 14212 KB | Output is correct |
54 | Correct | 87 ms | 14088 KB | Output is correct |
55 | Correct | 161 ms | 24120 KB | Output is correct |
56 | Correct | 171 ms | 24112 KB | Output is correct |
57 | Correct | 73 ms | 14212 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 0 ms | 212 KB | Output is correct |
60 | Correct | 4 ms | 824 KB | Output is correct |
61 | Correct | 85 ms | 13984 KB | Output is correct |
62 | Correct | 1 ms | 300 KB | Output is correct |
63 | Correct | 1 ms | 212 KB | Output is correct |
64 | Correct | 0 ms | 212 KB | Output is correct |
65 | Correct | 48 ms | 6292 KB | Output is correct |
66 | Correct | 74 ms | 14072 KB | Output is correct |
67 | Correct | 69 ms | 14084 KB | Output is correct |
68 | Correct | 77 ms | 14064 KB | Output is correct |
69 | Correct | 87 ms | 14216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 300 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1212 KB | Output is correct |
7 | Correct | 167 ms | 23984 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1236 KB | Output is correct |
13 | Correct | 157 ms | 24232 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 304 KB | Output is correct |
16 | Correct | 4 ms | 852 KB | Output is correct |
17 | Correct | 81 ms | 14072 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 40 ms | 6260 KB | Output is correct |
21 | Correct | 159 ms | 23988 KB | Output is correct |
22 | Correct | 158 ms | 24056 KB | Output is correct |
23 | Correct | 160 ms | 24012 KB | Output is correct |
24 | Correct | 161 ms | 24188 KB | Output is correct |
25 | Correct | 71 ms | 14084 KB | Output is correct |
26 | Correct | 70 ms | 14084 KB | Output is correct |
27 | Correct | 160 ms | 23924 KB | Output is correct |
28 | Correct | 158 ms | 24192 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 304 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 7 ms | 1208 KB | Output is correct |
37 | Correct | 158 ms | 24124 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 | 1212 KB | Output is correct |
41 | Correct | 166 ms | 24052 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 | 852 KB | Output is correct |
45 | Correct | 92 ms | 14068 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 39 ms | 6256 KB | Output is correct |
50 | Correct | 172 ms | 24052 KB | Output is correct |
51 | Correct | 157 ms | 24112 KB | Output is correct |
52 | Correct | 162 ms | 24052 KB | Output is correct |
53 | Correct | 72 ms | 14212 KB | Output is correct |
54 | Correct | 87 ms | 14088 KB | Output is correct |
55 | Correct | 161 ms | 24120 KB | Output is correct |
56 | Correct | 171 ms | 24112 KB | Output is correct |
57 | Correct | 73 ms | 14212 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 1 ms | 212 KB | Output is correct |
60 | Correct | 1 ms | 212 KB | Output is correct |
61 | Correct | 40 ms | 6244 KB | Output is correct |
62 | Correct | 176 ms | 24016 KB | Output is correct |
63 | Correct | 182 ms | 24056 KB | Output is correct |
64 | Correct | 161 ms | 23960 KB | Output is correct |
65 | Correct | 1 ms | 212 KB | Output is correct |
66 | Correct | 45 ms | 6308 KB | Output is correct |
67 | Correct | 161 ms | 24124 KB | Output is correct |
68 | Correct | 158 ms | 24148 KB | Output is correct |
69 | Correct | 167 ms | 24160 KB | Output is correct |
70 | Correct | 1 ms | 212 KB | Output is correct |
71 | Correct | 1 ms | 212 KB | Output is correct |
72 | Correct | 1 ms | 212 KB | Output is correct |
73 | Correct | 40 ms | 6220 KB | Output is correct |
74 | Correct | 171 ms | 24056 KB | Output is correct |
75 | Correct | 168 ms | 24060 KB | Output is correct |
76 | Correct | 162 ms | 24072 KB | Output is correct |
77 | Correct | 162 ms | 24180 KB | Output is correct |
78 | Correct | 1 ms | 212 KB | Output is correct |
79 | Correct | 0 ms | 212 KB | Output is correct |
80 | Correct | 4 ms | 824 KB | Output is correct |
81 | Correct | 85 ms | 13984 KB | Output is correct |
82 | Correct | 1 ms | 300 KB | Output is correct |
83 | Correct | 1 ms | 212 KB | Output is correct |
84 | Correct | 0 ms | 212 KB | Output is correct |
85 | Correct | 48 ms | 6292 KB | Output is correct |
86 | Correct | 74 ms | 14072 KB | Output is correct |
87 | Correct | 69 ms | 14084 KB | Output is correct |
88 | Correct | 77 ms | 14064 KB | Output is correct |
89 | Correct | 87 ms | 14216 KB | Output is correct |
90 | Correct | 1 ms | 212 KB | Output is correct |
91 | Correct | 0 ms | 212 KB | Output is correct |
92 | Correct | 3 ms | 696 KB | Output is correct |
93 | Correct | 67 ms | 10104 KB | Output is correct |
94 | Correct | 0 ms | 212 KB | Output is correct |
95 | Correct | 1 ms | 212 KB | Output is correct |
96 | Correct | 1 ms | 212 KB | Output is correct |
97 | Correct | 16 ms | 2772 KB | Output is correct |
98 | Correct | 66 ms | 10100 KB | Output is correct |
99 | Correct | 83 ms | 10100 KB | Output is correct |
100 | Correct | 67 ms | 10064 KB | Output is correct |
101 | Correct | 67 ms | 10104 KB | Output is correct |
102 | Correct | 71 ms | 10104 KB | Output is correct |
103 | Correct | 81 ms | 10112 KB | Output is correct |
104 | Correct | 66 ms | 10120 KB | Output is correct |
105 | Correct | 69 ms | 10104 KB | Output is correct |