#include "supertrees.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
static const int N = 1010;
static vector<int> one[N];
static vector<int> two[N];
static bool vis[N];
static int col[N];
static vector<vector<int>> B;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
B = vector<vector<int>>(n, vector<int>(n, 0));
Loop (i,0,n) Loop (j,0,n) {
if (p[i][j] == 3)
return 0;
}
int n1 = 0;
Loop (i,0,n) {
if (vis[i])
continue;
Loop (j,0,n)
if (p[i][j] == 1) {
one[n1].push_back(j);
vis[j] = 1;
col[j] = n1;
if (i != j)
B[i][j] = B[j][i] = 1;
}
for (int x : one[n1])
for (int y : one[n1])
if (p[x][y] != 1)
return 0;
++n1;
}
Loop (i,0,n1)
Loop (j,i+1,n1)
for (int x : one[i])
for (int y : one[j])
if (p[x][y] == 1)
return 0;
memset(vis, 0, sizeof(vis));
int n2 = 0;
Loop (i,0,n) {
if (vis[col[i]])
continue;
vis[col[i]] = 1;
two[n2].push_back(col[i]);
Loop (j,0,n)
if (p[i][j] == 2) {
if (!vis[col[j]]) {
two[n2].push_back(col[j]);
vis[col[j]] = 1;
}
}
if (two[n2].size() == 1) {
n2++;
continue;
}
for (int x : two[n2])
for (int y : two[n2])
if (x != y)
for (int a : one[x])
for (int b : one[y])
if (p[a][b] != 2)
return 0;
if (two[n2].size() == 2) {
if (one[two[n2][0]].size() >= 2) {
B[one[two[n2][0]][0]][one[two[n2][1]][0]] = 1;
B[one[two[n2][1]][0]][one[two[n2][0]][0]] = 1;
B[one[two[n2][0]][1]][one[two[n2][1]][0]] = 1;
B[one[two[n2][1]][0]][one[two[n2][0]][1]] = 1;
} else if (one[two[n2][1]].size() >= 2) {
B[one[two[n2][0]][0]][one[two[n2][1]][0]] = 1;
B[one[two[n2][1]][0]][one[two[n2][0]][0]] = 1;
B[one[two[n2][0]][0]][one[two[n2][1]][1]] = 1;
B[one[two[n2][1]][1]][one[two[n2][0]][0]] = 1;
} else {
return 0;
}
}
if (two[n2].size() >= 3) {
Loop (i,0,two[n2].size()) {
int j = (i+1) % two[n2].size();
B[one[two[n2][i]][0]][one[two[n2][j]][0]] = 1;
B[one[two[n2][j]][0]][one[two[n2][i]][0]] = 1;
}
}
n2++;
}
Loop (i,0,n2)
Loop (j,i+1,n2)
for (int x : two[i])
for (int y : two[j])
for (int a : one[x])
for (int b : one[y])
if (p[a][b])
return 0;
build(B);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
| ^
supertrees.cpp:90:4: note: in expansion of macro 'Loop'
90 | Loop (i,0,two[n2].size()) {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1268 KB |
Output is correct |
7 |
Correct |
156 ms |
22228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1268 KB |
Output is correct |
7 |
Correct |
156 ms |
22228 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
160 ms |
22208 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
72 ms |
12216 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
42 ms |
5836 KB |
Output is correct |
21 |
Correct |
161 ms |
22204 KB |
Output is correct |
22 |
Correct |
158 ms |
22232 KB |
Output is correct |
23 |
Correct |
176 ms |
22220 KB |
Output is correct |
24 |
Correct |
167 ms |
22228 KB |
Output is correct |
25 |
Correct |
67 ms |
12236 KB |
Output is correct |
26 |
Correct |
65 ms |
12264 KB |
Output is correct |
27 |
Correct |
167 ms |
22152 KB |
Output is correct |
28 |
Correct |
162 ms |
22220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
356 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
11 ms |
1236 KB |
Output is correct |
9 |
Correct |
165 ms |
22324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1316 KB |
Output is correct |
13 |
Correct |
166 ms |
22308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
73 ms |
12476 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
41 ms |
5980 KB |
Output is correct |
22 |
Correct |
172 ms |
22296 KB |
Output is correct |
23 |
Correct |
159 ms |
22340 KB |
Output is correct |
24 |
Correct |
181 ms |
22504 KB |
Output is correct |
25 |
Correct |
68 ms |
12368 KB |
Output is correct |
26 |
Correct |
73 ms |
12384 KB |
Output is correct |
27 |
Correct |
158 ms |
22344 KB |
Output is correct |
28 |
Correct |
183 ms |
22352 KB |
Output is correct |
29 |
Correct |
66 ms |
12472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
43 ms |
5944 KB |
Output is correct |
5 |
Correct |
163 ms |
22280 KB |
Output is correct |
6 |
Correct |
168 ms |
22324 KB |
Output is correct |
7 |
Correct |
164 ms |
22272 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
50 ms |
6008 KB |
Output is correct |
10 |
Correct |
162 ms |
22340 KB |
Output is correct |
11 |
Correct |
168 ms |
22316 KB |
Output is correct |
12 |
Correct |
176 ms |
22368 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
42 ms |
5964 KB |
Output is correct |
17 |
Correct |
164 ms |
23980 KB |
Output is correct |
18 |
Correct |
165 ms |
24016 KB |
Output is correct |
19 |
Correct |
161 ms |
24120 KB |
Output is correct |
20 |
Correct |
159 ms |
24012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1268 KB |
Output is correct |
7 |
Correct |
156 ms |
22228 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
160 ms |
22208 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
72 ms |
12216 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
42 ms |
5836 KB |
Output is correct |
21 |
Correct |
161 ms |
22204 KB |
Output is correct |
22 |
Correct |
158 ms |
22232 KB |
Output is correct |
23 |
Correct |
176 ms |
22220 KB |
Output is correct |
24 |
Correct |
167 ms |
22228 KB |
Output is correct |
25 |
Correct |
67 ms |
12236 KB |
Output is correct |
26 |
Correct |
65 ms |
12264 KB |
Output is correct |
27 |
Correct |
167 ms |
22152 KB |
Output is correct |
28 |
Correct |
162 ms |
22220 KB |
Output is correct |
29 |
Correct |
1 ms |
356 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
352 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
356 KB |
Output is correct |
34 |
Correct |
1 ms |
352 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
11 ms |
1236 KB |
Output is correct |
37 |
Correct |
165 ms |
22324 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1316 KB |
Output is correct |
41 |
Correct |
166 ms |
22308 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
73 ms |
12476 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
41 ms |
5980 KB |
Output is correct |
50 |
Correct |
172 ms |
22296 KB |
Output is correct |
51 |
Correct |
159 ms |
22340 KB |
Output is correct |
52 |
Correct |
181 ms |
22504 KB |
Output is correct |
53 |
Correct |
68 ms |
12368 KB |
Output is correct |
54 |
Correct |
73 ms |
12384 KB |
Output is correct |
55 |
Correct |
158 ms |
22344 KB |
Output is correct |
56 |
Correct |
183 ms |
22352 KB |
Output is correct |
57 |
Correct |
66 ms |
12472 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
3 ms |
852 KB |
Output is correct |
61 |
Correct |
96 ms |
12348 KB |
Output is correct |
62 |
Correct |
0 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
42 ms |
6000 KB |
Output is correct |
66 |
Correct |
71 ms |
14180 KB |
Output is correct |
67 |
Correct |
64 ms |
14120 KB |
Output is correct |
68 |
Correct |
66 ms |
14120 KB |
Output is correct |
69 |
Correct |
64 ms |
14136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1268 KB |
Output is correct |
7 |
Correct |
156 ms |
22228 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
160 ms |
22208 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
72 ms |
12216 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
42 ms |
5836 KB |
Output is correct |
21 |
Correct |
161 ms |
22204 KB |
Output is correct |
22 |
Correct |
158 ms |
22232 KB |
Output is correct |
23 |
Correct |
176 ms |
22220 KB |
Output is correct |
24 |
Correct |
167 ms |
22228 KB |
Output is correct |
25 |
Correct |
67 ms |
12236 KB |
Output is correct |
26 |
Correct |
65 ms |
12264 KB |
Output is correct |
27 |
Correct |
167 ms |
22152 KB |
Output is correct |
28 |
Correct |
162 ms |
22220 KB |
Output is correct |
29 |
Correct |
1 ms |
356 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
352 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
356 KB |
Output is correct |
34 |
Correct |
1 ms |
352 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
11 ms |
1236 KB |
Output is correct |
37 |
Correct |
165 ms |
22324 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1316 KB |
Output is correct |
41 |
Correct |
166 ms |
22308 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
73 ms |
12476 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
41 ms |
5980 KB |
Output is correct |
50 |
Correct |
172 ms |
22296 KB |
Output is correct |
51 |
Correct |
159 ms |
22340 KB |
Output is correct |
52 |
Correct |
181 ms |
22504 KB |
Output is correct |
53 |
Correct |
68 ms |
12368 KB |
Output is correct |
54 |
Correct |
73 ms |
12384 KB |
Output is correct |
55 |
Correct |
158 ms |
22344 KB |
Output is correct |
56 |
Correct |
183 ms |
22352 KB |
Output is correct |
57 |
Correct |
66 ms |
12472 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
43 ms |
5944 KB |
Output is correct |
62 |
Correct |
163 ms |
22280 KB |
Output is correct |
63 |
Correct |
168 ms |
22324 KB |
Output is correct |
64 |
Correct |
164 ms |
22272 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
50 ms |
6008 KB |
Output is correct |
67 |
Correct |
162 ms |
22340 KB |
Output is correct |
68 |
Correct |
168 ms |
22316 KB |
Output is correct |
69 |
Correct |
176 ms |
22368 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
42 ms |
5964 KB |
Output is correct |
74 |
Correct |
164 ms |
23980 KB |
Output is correct |
75 |
Correct |
165 ms |
24016 KB |
Output is correct |
76 |
Correct |
161 ms |
24120 KB |
Output is correct |
77 |
Correct |
159 ms |
24012 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
3 ms |
852 KB |
Output is correct |
81 |
Correct |
96 ms |
12348 KB |
Output is correct |
82 |
Correct |
0 ms |
340 KB |
Output is correct |
83 |
Correct |
1 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
42 ms |
6000 KB |
Output is correct |
86 |
Correct |
71 ms |
14180 KB |
Output is correct |
87 |
Correct |
64 ms |
14120 KB |
Output is correct |
88 |
Correct |
66 ms |
14120 KB |
Output is correct |
89 |
Correct |
64 ms |
14136 KB |
Output is correct |
90 |
Correct |
1 ms |
352 KB |
Output is correct |
91 |
Correct |
1 ms |
340 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
70 ms |
14132 KB |
Output is correct |
94 |
Correct |
0 ms |
340 KB |
Output is correct |
95 |
Correct |
0 ms |
340 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
20 ms |
3756 KB |
Output is correct |
98 |
Correct |
65 ms |
14140 KB |
Output is correct |
99 |
Correct |
67 ms |
14140 KB |
Output is correct |
100 |
Correct |
66 ms |
14128 KB |
Output is correct |
101 |
Correct |
62 ms |
14136 KB |
Output is correct |
102 |
Correct |
65 ms |
14128 KB |
Output is correct |
103 |
Correct |
62 ms |
14124 KB |
Output is correct |
104 |
Correct |
63 ms |
14052 KB |
Output is correct |
105 |
Correct |
71 ms |
14156 KB |
Output is correct |