# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
576791 | 2022-06-13T13:47:32 Z | nghiass001 | Connecting Supertrees (IOI20_supertrees) | C++17 | 200 ms | 26064 KB |
#include <bits/stdc++.h> #define FOR(i,l,r) for(int i=(l); i<=(r); ++i) #define REP(i,l,r) for(int i=(l); i<(r); ++i) #define FORD(i,r,l) for(int i=(r); i>=(l); --i) #define REPD(i,r,l) for(int i=(r)-1; i>=(l); --i) using namespace std; const int N = 1e3 + 5; int nn, avail[N]; vector<vector<int>> adj; vector<int> Q, List; void build(vector<vector<int>> b); void DFS(int u) { Q.push_back(u); avail[u] = 1; REP(v, 0, nn) if (adj[u][v] == 1 && avail[v] == 0) DFS(v); } void DFS2(int u) { Q.push_back(u); avail[u] = 1; for(int v : List) if (adj[u][v] == 2 && avail[v] == 0) DFS2(v); } void DFS3(int u) { Q.push_back(u); avail[u] = 1; for(int v : List) if (adj[u][v] == 3 && avail[v] == 0) DFS2(v); } int construct(vector<vector<int>> p) { adj = p; nn = p.size(); vector<vector<int>> ans(nn, vector<int>(nn, 0)); REP(i, 0, nn) if (avail[i] == 0) { Q.clear(); DFS(i); for(int u : Q) if (p[i] != p[u]) return 0; REP(i, 1, Q.size()) ans[Q[i - 1]][Q[i]] = ans[Q[i]][Q[i - 1]] = 1; List.push_back(i); } fill(avail, avail + nn, 0); for(int i : List) if (avail[i] == 0) { Q.clear(); DFS2(i); if (Q.size() == 1) continue; if (Q.size() == 2) return 0; for(int u : Q) for(int v : Q) if (u != v && adj[u][v] != 2) return 0; REP(i, 1, Q.size()) ans[Q[i - 1]][Q[i]] = ans[Q[i]][Q[i - 1]] = 1; ans[Q[0]][Q.back()] = ans[Q.back()][Q[0]] = 1; } fill(avail, avail + nn, 0); for(int i : List) if (avail[i] == 0) { Q.clear(); DFS3(i); if (Q.size() == 1) continue; return 0; if (Q.size() == 2) return 0; if (Q.size() == 3) return 0; for(int u : Q) for(int v : Q) if (u != v && adj[u][v] != 3) return 0; REP(i, 1, Q.size()) ans[Q[i - 1]][Q[i]] = ans[Q[i]][Q[i - 1]] = 1; ans[Q[0]][Q.back()] = ans[Q.back()][Q[0]] = 1; ans[Q[0]][Q[2]] = ans[Q[2]][Q[0]] = 1; } build(ans); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1356 KB | Output is correct |
7 | Correct | 180 ms | 26060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1356 KB | Output is correct |
7 | Correct | 180 ms | 26060 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1336 KB | Output is correct |
13 | Correct | 167 ms | 25932 KB | Output is correct |
14 | Correct | 0 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 | 83 ms | 16136 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 46 ms | 6724 KB | Output is correct |
21 | Correct | 200 ms | 26016 KB | Output is correct |
22 | Correct | 162 ms | 25940 KB | Output is correct |
23 | Correct | 176 ms | 26000 KB | Output is correct |
24 | Correct | 169 ms | 25932 KB | Output is correct |
25 | Correct | 69 ms | 16004 KB | Output is correct |
26 | Correct | 100 ms | 16004 KB | Output is correct |
27 | Correct | 190 ms | 25980 KB | Output is correct |
28 | Correct | 168 ms | 25932 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 | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 8 ms | 1292 KB | Output is correct |
9 | Correct | 177 ms | 26004 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1364 KB | Output is correct |
13 | Correct | 172 ms | 26008 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 6 ms | 852 KB | Output is correct |
17 | Correct | 88 ms | 16136 KB | Output is correct |
18 | Correct | 0 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 | 44 ms | 6732 KB | Output is correct |
22 | Correct | 172 ms | 26004 KB | Output is correct |
23 | Correct | 181 ms | 26004 KB | Output is correct |
24 | Correct | 175 ms | 25948 KB | Output is correct |
25 | Correct | 95 ms | 16008 KB | Output is correct |
26 | Correct | 73 ms | 16008 KB | Output is correct |
27 | Correct | 161 ms | 26052 KB | Output is correct |
28 | Correct | 196 ms | 26004 KB | Output is correct |
29 | Correct | 70 ms | 16076 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 | 1 ms | 212 KB | Output is correct |
4 | Correct | 55 ms | 6732 KB | Output is correct |
5 | Correct | 179 ms | 26000 KB | Output is correct |
6 | Correct | 161 ms | 26012 KB | Output is correct |
7 | Correct | 188 ms | 26008 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 45 ms | 6676 KB | Output is correct |
10 | Correct | 192 ms | 26064 KB | Output is correct |
11 | Correct | 171 ms | 26000 KB | Output is correct |
12 | Correct | 190 ms | 25936 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 55 ms | 6696 KB | Output is correct |
17 | Correct | 166 ms | 25992 KB | Output is correct |
18 | Correct | 174 ms | 25932 KB | Output is correct |
19 | Correct | 177 ms | 26004 KB | Output is correct |
20 | Correct | 178 ms | 25928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1356 KB | Output is correct |
7 | Correct | 180 ms | 26060 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1336 KB | Output is correct |
13 | Correct | 167 ms | 25932 KB | Output is correct |
14 | Correct | 0 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 | 83 ms | 16136 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 46 ms | 6724 KB | Output is correct |
21 | Correct | 200 ms | 26016 KB | Output is correct |
22 | Correct | 162 ms | 25940 KB | Output is correct |
23 | Correct | 176 ms | 26000 KB | Output is correct |
24 | Correct | 169 ms | 25932 KB | Output is correct |
25 | Correct | 69 ms | 16004 KB | Output is correct |
26 | Correct | 100 ms | 16004 KB | Output is correct |
27 | Correct | 190 ms | 25980 KB | Output is correct |
28 | Correct | 168 ms | 25932 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 | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 8 ms | 1292 KB | Output is correct |
37 | Correct | 177 ms | 26004 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 7 ms | 1364 KB | Output is correct |
41 | Correct | 172 ms | 26008 KB | Output is correct |
42 | Correct | 0 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 212 KB | Output is correct |
44 | Correct | 6 ms | 852 KB | Output is correct |
45 | Correct | 88 ms | 16136 KB | Output is correct |
46 | Correct | 0 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 | 44 ms | 6732 KB | Output is correct |
50 | Correct | 172 ms | 26004 KB | Output is correct |
51 | Correct | 181 ms | 26004 KB | Output is correct |
52 | Correct | 175 ms | 25948 KB | Output is correct |
53 | Correct | 95 ms | 16008 KB | Output is correct |
54 | Correct | 73 ms | 16008 KB | Output is correct |
55 | Correct | 161 ms | 26052 KB | Output is correct |
56 | Correct | 196 ms | 26004 KB | Output is correct |
57 | Correct | 70 ms | 16076 KB | Output is correct |
58 | Correct | 0 ms | 212 KB | Output is correct |
59 | Correct | 0 ms | 212 KB | Output is correct |
60 | Correct | 4 ms | 852 KB | Output is correct |
61 | Correct | 108 ms | 16148 KB | Output is correct |
62 | Correct | 0 ms | 212 KB | Output is correct |
63 | Correct | 0 ms | 212 KB | Output is correct |
64 | Correct | 0 ms | 212 KB | Output is correct |
65 | Correct | 44 ms | 6660 KB | Output is correct |
66 | Correct | 69 ms | 16008 KB | Output is correct |
67 | Correct | 72 ms | 16008 KB | Output is correct |
68 | Correct | 78 ms | 16012 KB | Output is correct |
69 | Correct | 82 ms | 16004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1356 KB | Output is correct |
7 | Correct | 180 ms | 26060 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1336 KB | Output is correct |
13 | Correct | 167 ms | 25932 KB | Output is correct |
14 | Correct | 0 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 | 83 ms | 16136 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 46 ms | 6724 KB | Output is correct |
21 | Correct | 200 ms | 26016 KB | Output is correct |
22 | Correct | 162 ms | 25940 KB | Output is correct |
23 | Correct | 176 ms | 26000 KB | Output is correct |
24 | Correct | 169 ms | 25932 KB | Output is correct |
25 | Correct | 69 ms | 16004 KB | Output is correct |
26 | Correct | 100 ms | 16004 KB | Output is correct |
27 | Correct | 190 ms | 25980 KB | Output is correct |
28 | Correct | 168 ms | 25932 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 | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 8 ms | 1292 KB | Output is correct |
37 | Correct | 177 ms | 26004 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 7 ms | 1364 KB | Output is correct |
41 | Correct | 172 ms | 26008 KB | Output is correct |
42 | Correct | 0 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 212 KB | Output is correct |
44 | Correct | 6 ms | 852 KB | Output is correct |
45 | Correct | 88 ms | 16136 KB | Output is correct |
46 | Correct | 0 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 | 44 ms | 6732 KB | Output is correct |
50 | Correct | 172 ms | 26004 KB | Output is correct |
51 | Correct | 181 ms | 26004 KB | Output is correct |
52 | Correct | 175 ms | 25948 KB | Output is correct |
53 | Correct | 95 ms | 16008 KB | Output is correct |
54 | Correct | 73 ms | 16008 KB | Output is correct |
55 | Correct | 161 ms | 26052 KB | Output is correct |
56 | Correct | 196 ms | 26004 KB | Output is correct |
57 | Correct | 70 ms | 16076 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 0 ms | 212 KB | Output is correct |
60 | Correct | 1 ms | 212 KB | Output is correct |
61 | Correct | 55 ms | 6732 KB | Output is correct |
62 | Correct | 179 ms | 26000 KB | Output is correct |
63 | Correct | 161 ms | 26012 KB | Output is correct |
64 | Correct | 188 ms | 26008 KB | Output is correct |
65 | Correct | 1 ms | 212 KB | Output is correct |
66 | Correct | 45 ms | 6676 KB | Output is correct |
67 | Correct | 192 ms | 26064 KB | Output is correct |
68 | Correct | 171 ms | 26000 KB | Output is correct |
69 | Correct | 190 ms | 25936 KB | Output is correct |
70 | Correct | 1 ms | 212 KB | Output is correct |
71 | Correct | 0 ms | 212 KB | Output is correct |
72 | Correct | 1 ms | 212 KB | Output is correct |
73 | Correct | 55 ms | 6696 KB | Output is correct |
74 | Correct | 166 ms | 25992 KB | Output is correct |
75 | Correct | 174 ms | 25932 KB | Output is correct |
76 | Correct | 177 ms | 26004 KB | Output is correct |
77 | Correct | 178 ms | 25928 KB | Output is correct |
78 | Correct | 0 ms | 212 KB | Output is correct |
79 | Correct | 0 ms | 212 KB | Output is correct |
80 | Correct | 4 ms | 852 KB | Output is correct |
81 | Correct | 108 ms | 16148 KB | Output is correct |
82 | Correct | 0 ms | 212 KB | Output is correct |
83 | Correct | 0 ms | 212 KB | Output is correct |
84 | Correct | 0 ms | 212 KB | Output is correct |
85 | Correct | 44 ms | 6660 KB | Output is correct |
86 | Correct | 69 ms | 16008 KB | Output is correct |
87 | Correct | 72 ms | 16008 KB | Output is correct |
88 | Correct | 78 ms | 16012 KB | Output is correct |
89 | Correct | 82 ms | 16004 KB | Output is correct |
90 | Correct | 0 ms | 212 KB | Output is correct |
91 | Correct | 0 ms | 212 KB | Output is correct |
92 | Correct | 4 ms | 852 KB | Output is correct |
93 | Correct | 84 ms | 16144 KB | Output is correct |
94 | Correct | 0 ms | 212 KB | Output is correct |
95 | Correct | 0 ms | 212 KB | Output is correct |
96 | Correct | 1 ms | 212 KB | Output is correct |
97 | Correct | 18 ms | 4240 KB | Output is correct |
98 | Correct | 75 ms | 16008 KB | Output is correct |
99 | Correct | 82 ms | 16012 KB | Output is correct |
100 | Correct | 76 ms | 16024 KB | Output is correct |
101 | Correct | 70 ms | 16024 KB | Output is correct |
102 | Correct | 72 ms | 16076 KB | Output is correct |
103 | Correct | 80 ms | 18036 KB | Output is correct |
104 | Correct | 85 ms | 18084 KB | Output is correct |
105 | Correct | 115 ms | 18040 KB | Output is correct |