#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e3 + 42;
bool repr[N];
int n, par[N];
vector<int> cycle[N];
int F(int i) {
if(par[i] == i)
return i;
return par[i] = F(par[i]);
}
void U(int a, int b) {
a = F(a), b = F(b);
if(a != b)
repr[a] = false;
par[a] = b;
}
int construct(vector<vector<int>> p) {
n = p[0].size();
for(int i = 0; i < n; i++) {
par[i] = i;
repr[i] = true;
cycle[i].clear();
}
vector<vector<int>> b(n);
for(int i = 0; i < n; i++)
b[i].resize(n);
for(int i = 0; i < n; i++)
for(int j = i+1; j < n; j++)
if(p[i][j] == 1)
U(i, j);
else if(p[i][j] == 3)
return 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(p[i][j] != p[F(i)][j])
return 0;
for(int i = 0; i < n; i++)
if(i != F(i))
b[i][F(i)] = 1;
vector<int> rep;
for(int i = 0; i < n; i++)
if(i == par[i])
rep.push_back(i);
for(int i : rep)
for(int j : rep)
if(p[i][j] == 2)
U(i, j);
for(int i : rep)
for(int j : rep)
if(i != j && F(i) == F(j) && p[i][j] != 2)
return 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(F(i) == F(j) && p[i][j] == 0)
return 0;
for(int i : rep)
cycle[F(i)].push_back(i);
for(int i = 0; i < n; i++) {
if(i == par[i]) {
int sz = cycle[i].size();
if(sz == 2)
return 0;
for(int j = 0; j < sz; j++)
b[cycle[i][j]][cycle[i][(j+1) % sz]] = 1;
}
}
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(b[i][j] || b[j][i])
b[i][j] = b[j][i] = 1;
for(int i = 0; i < n; i++)
b[i][i] = 0;
build(b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1232 KB |
Output is correct |
7 |
Correct |
205 ms |
22636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1232 KB |
Output is correct |
7 |
Correct |
205 ms |
22636 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 |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
203 ms |
22696 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
88 ms |
12704 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
6212 KB |
Output is correct |
21 |
Correct |
192 ms |
22616 KB |
Output is correct |
22 |
Correct |
191 ms |
22620 KB |
Output is correct |
23 |
Correct |
209 ms |
22648 KB |
Output is correct |
24 |
Correct |
256 ms |
22660 KB |
Output is correct |
25 |
Correct |
77 ms |
12708 KB |
Output is correct |
26 |
Correct |
74 ms |
12724 KB |
Output is correct |
27 |
Correct |
221 ms |
22612 KB |
Output is correct |
28 |
Correct |
214 ms |
22672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
11 ms |
1236 KB |
Output is correct |
9 |
Correct |
211 ms |
24092 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
360 KB |
Output is correct |
12 |
Correct |
9 ms |
1236 KB |
Output is correct |
13 |
Correct |
195 ms |
23952 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
115 ms |
14096 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
49 ms |
6220 KB |
Output is correct |
22 |
Correct |
192 ms |
23960 KB |
Output is correct |
23 |
Correct |
201 ms |
24012 KB |
Output is correct |
24 |
Correct |
232 ms |
24028 KB |
Output is correct |
25 |
Correct |
101 ms |
14148 KB |
Output is correct |
26 |
Correct |
79 ms |
14096 KB |
Output is correct |
27 |
Correct |
257 ms |
23964 KB |
Output is correct |
28 |
Correct |
244 ms |
23932 KB |
Output is correct |
29 |
Correct |
89 ms |
14108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
87 ms |
6192 KB |
Output is correct |
5 |
Correct |
258 ms |
22680 KB |
Output is correct |
6 |
Correct |
210 ms |
22624 KB |
Output is correct |
7 |
Correct |
213 ms |
22792 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
65 ms |
6220 KB |
Output is correct |
10 |
Correct |
244 ms |
22660 KB |
Output is correct |
11 |
Correct |
219 ms |
22736 KB |
Output is correct |
12 |
Correct |
247 ms |
22644 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
69 ms |
6280 KB |
Output is correct |
17 |
Correct |
346 ms |
22664 KB |
Output is correct |
18 |
Correct |
244 ms |
22716 KB |
Output is correct |
19 |
Correct |
233 ms |
22684 KB |
Output is correct |
20 |
Correct |
263 ms |
22688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1232 KB |
Output is correct |
7 |
Correct |
205 ms |
22636 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 |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
203 ms |
22696 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
88 ms |
12704 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
6212 KB |
Output is correct |
21 |
Correct |
192 ms |
22616 KB |
Output is correct |
22 |
Correct |
191 ms |
22620 KB |
Output is correct |
23 |
Correct |
209 ms |
22648 KB |
Output is correct |
24 |
Correct |
256 ms |
22660 KB |
Output is correct |
25 |
Correct |
77 ms |
12708 KB |
Output is correct |
26 |
Correct |
74 ms |
12724 KB |
Output is correct |
27 |
Correct |
221 ms |
22612 KB |
Output is correct |
28 |
Correct |
214 ms |
22672 KB |
Output is correct |
29 |
Correct |
0 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 |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
11 ms |
1236 KB |
Output is correct |
37 |
Correct |
211 ms |
24092 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
360 KB |
Output is correct |
40 |
Correct |
9 ms |
1236 KB |
Output is correct |
41 |
Correct |
195 ms |
23952 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
5 ms |
852 KB |
Output is correct |
45 |
Correct |
115 ms |
14096 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
49 ms |
6220 KB |
Output is correct |
50 |
Correct |
192 ms |
23960 KB |
Output is correct |
51 |
Correct |
201 ms |
24012 KB |
Output is correct |
52 |
Correct |
232 ms |
24028 KB |
Output is correct |
53 |
Correct |
101 ms |
14148 KB |
Output is correct |
54 |
Correct |
79 ms |
14096 KB |
Output is correct |
55 |
Correct |
257 ms |
23964 KB |
Output is correct |
56 |
Correct |
244 ms |
23932 KB |
Output is correct |
57 |
Correct |
89 ms |
14108 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
105 ms |
14020 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
66 ms |
6244 KB |
Output is correct |
66 |
Correct |
83 ms |
14116 KB |
Output is correct |
67 |
Correct |
305 ms |
14096 KB |
Output is correct |
68 |
Correct |
133 ms |
14096 KB |
Output is correct |
69 |
Correct |
115 ms |
14096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1232 KB |
Output is correct |
7 |
Correct |
205 ms |
22636 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 |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
203 ms |
22696 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
88 ms |
12704 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
6212 KB |
Output is correct |
21 |
Correct |
192 ms |
22616 KB |
Output is correct |
22 |
Correct |
191 ms |
22620 KB |
Output is correct |
23 |
Correct |
209 ms |
22648 KB |
Output is correct |
24 |
Correct |
256 ms |
22660 KB |
Output is correct |
25 |
Correct |
77 ms |
12708 KB |
Output is correct |
26 |
Correct |
74 ms |
12724 KB |
Output is correct |
27 |
Correct |
221 ms |
22612 KB |
Output is correct |
28 |
Correct |
214 ms |
22672 KB |
Output is correct |
29 |
Correct |
0 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 |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
11 ms |
1236 KB |
Output is correct |
37 |
Correct |
211 ms |
24092 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
360 KB |
Output is correct |
40 |
Correct |
9 ms |
1236 KB |
Output is correct |
41 |
Correct |
195 ms |
23952 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
5 ms |
852 KB |
Output is correct |
45 |
Correct |
115 ms |
14096 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
49 ms |
6220 KB |
Output is correct |
50 |
Correct |
192 ms |
23960 KB |
Output is correct |
51 |
Correct |
201 ms |
24012 KB |
Output is correct |
52 |
Correct |
232 ms |
24028 KB |
Output is correct |
53 |
Correct |
101 ms |
14148 KB |
Output is correct |
54 |
Correct |
79 ms |
14096 KB |
Output is correct |
55 |
Correct |
257 ms |
23964 KB |
Output is correct |
56 |
Correct |
244 ms |
23932 KB |
Output is correct |
57 |
Correct |
89 ms |
14108 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
87 ms |
6192 KB |
Output is correct |
62 |
Correct |
258 ms |
22680 KB |
Output is correct |
63 |
Correct |
210 ms |
22624 KB |
Output is correct |
64 |
Correct |
213 ms |
22792 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
65 ms |
6220 KB |
Output is correct |
67 |
Correct |
244 ms |
22660 KB |
Output is correct |
68 |
Correct |
219 ms |
22736 KB |
Output is correct |
69 |
Correct |
247 ms |
22644 KB |
Output is correct |
70 |
Correct |
1 ms |
328 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
69 ms |
6280 KB |
Output is correct |
74 |
Correct |
346 ms |
22664 KB |
Output is correct |
75 |
Correct |
244 ms |
22716 KB |
Output is correct |
76 |
Correct |
233 ms |
22684 KB |
Output is correct |
77 |
Correct |
263 ms |
22688 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
4 ms |
852 KB |
Output is correct |
81 |
Correct |
105 ms |
14020 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
66 ms |
6244 KB |
Output is correct |
86 |
Correct |
83 ms |
14116 KB |
Output is correct |
87 |
Correct |
305 ms |
14096 KB |
Output is correct |
88 |
Correct |
133 ms |
14096 KB |
Output is correct |
89 |
Correct |
115 ms |
14096 KB |
Output is correct |
90 |
Correct |
1 ms |
328 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
852 KB |
Output is correct |
93 |
Correct |
78 ms |
14100 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
3 ms |
212 KB |
Output is correct |
97 |
Correct |
29 ms |
3728 KB |
Output is correct |
98 |
Correct |
96 ms |
14100 KB |
Output is correct |
99 |
Correct |
105 ms |
14124 KB |
Output is correct |
100 |
Correct |
110 ms |
14100 KB |
Output is correct |
101 |
Correct |
77 ms |
14028 KB |
Output is correct |
102 |
Correct |
95 ms |
14028 KB |
Output is correct |
103 |
Correct |
78 ms |
14092 KB |
Output is correct |
104 |
Correct |
113 ms |
14100 KB |
Output is correct |
105 |
Correct |
133 ms |
14096 KB |
Output is correct |