#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
void dfs(int head, vector<vector<int>> &arr, vector<int> &vis, vector<vector<int>> &path, int N, vector<int> &col, int c){
vis[head] = true;
col[head] = c;
for(int i = 0; i < N; i ++){
if(!vis[i] && arr[head][i] == 1){
path[i][head] = 1;
path[head][i] = 1;
dfs(i, arr, vis, path, N, col, c);
}
}
}
void dfs2(int head, vector<vector<int>> &path, int N, int &e, vector<int> &vis, vector<vector<int>> &arr, vector<int> &col){
vis[head] = true;
for(int i = 0; i < N; i ++){
if(col[i] == col[head]){
vis[i] = true;
}
}
e = head;
for(int i = 0; i < N; i ++){
if(!vis[i] && arr[head][i] == 2){
int c = col[i];
for(int j = 0; j < N; j ++){
if(col[j] == c){
col[j] = col[head];
}
}
path[i][head] = 1;
path[head][i] = 1;
dfs2(i, path, N, e, vis, arr, col);
}
}
}
int construct(vector<vector<int>> arr){
int N = arr.size();
vector<int> vis(N, 0), col(N, -1);
bool pos = true;
vector<vector<int>> path(N, vector<int>(N));
int c = 1;
for(int i = 0; i < N; i ++){
if(!vis[i]){
dfs(i, arr, vis, path, N, col, c++);
}
}
fill(vis.begin(), vis.end(), 0);
for(int i = 0; i < N; i ++){
if(!vis[i] && *max_element(arr[i].begin(), arr[i].end()) == 2){
int t = -1;
dfs2(i, path, N, t, vis, arr, col);
if(path[i][t]){
pos = false;
}
path[i][t] = 1;
path[t][i] = 1;
}
}
for(int i = 0; i < N; i ++){
for(int j = 0; j < N; j ++){
if(arr[i][j] == 0 && col[i] == col[j]){
pos = false;
}
if(arr[i][j] == 3){
pos = false;
}
}
}
if(pos)
build(path);
return pos;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 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 |
304 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
160 ms |
22600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 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 |
304 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
160 ms |
22600 KB |
Output is correct |
8 |
Correct |
1 ms |
300 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 |
296 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
167 ms |
22480 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 |
796 KB |
Output is correct |
17 |
Correct |
82 ms |
13600 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
6104 KB |
Output is correct |
21 |
Correct |
190 ms |
22476 KB |
Output is correct |
22 |
Correct |
157 ms |
22544 KB |
Output is correct |
23 |
Correct |
206 ms |
22500 KB |
Output is correct |
24 |
Correct |
156 ms |
22464 KB |
Output is correct |
25 |
Correct |
76 ms |
13548 KB |
Output is correct |
26 |
Correct |
92 ms |
13532 KB |
Output is correct |
27 |
Correct |
168 ms |
22532 KB |
Output is correct |
28 |
Correct |
155 ms |
22488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
152 ms |
22556 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 |
178 ms |
22580 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
75 ms |
13660 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 |
300 KB |
Output is correct |
21 |
Correct |
42 ms |
6168 KB |
Output is correct |
22 |
Correct |
159 ms |
22560 KB |
Output is correct |
23 |
Correct |
158 ms |
22452 KB |
Output is correct |
24 |
Correct |
159 ms |
22596 KB |
Output is correct |
25 |
Correct |
69 ms |
13548 KB |
Output is correct |
26 |
Correct |
70 ms |
13544 KB |
Output is correct |
27 |
Correct |
164 ms |
22564 KB |
Output is correct |
28 |
Correct |
200 ms |
22532 KB |
Output is correct |
29 |
Correct |
68 ms |
13404 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 |
41 ms |
6056 KB |
Output is correct |
5 |
Correct |
159 ms |
22448 KB |
Output is correct |
6 |
Correct |
160 ms |
22468 KB |
Output is correct |
7 |
Correct |
158 ms |
22476 KB |
Output is correct |
8 |
Correct |
0 ms |
292 KB |
Output is correct |
9 |
Correct |
39 ms |
5976 KB |
Output is correct |
10 |
Correct |
161 ms |
22568 KB |
Output is correct |
11 |
Correct |
157 ms |
22420 KB |
Output is correct |
12 |
Correct |
158 ms |
22472 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
39 ms |
5936 KB |
Output is correct |
17 |
Correct |
159 ms |
22436 KB |
Output is correct |
18 |
Correct |
158 ms |
22348 KB |
Output is correct |
19 |
Correct |
158 ms |
22448 KB |
Output is correct |
20 |
Correct |
154 ms |
22356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 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 |
304 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
160 ms |
22600 KB |
Output is correct |
8 |
Correct |
1 ms |
300 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 |
296 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
167 ms |
22480 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 |
796 KB |
Output is correct |
17 |
Correct |
82 ms |
13600 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
6104 KB |
Output is correct |
21 |
Correct |
190 ms |
22476 KB |
Output is correct |
22 |
Correct |
157 ms |
22544 KB |
Output is correct |
23 |
Correct |
206 ms |
22500 KB |
Output is correct |
24 |
Correct |
156 ms |
22464 KB |
Output is correct |
25 |
Correct |
76 ms |
13548 KB |
Output is correct |
26 |
Correct |
92 ms |
13532 KB |
Output is correct |
27 |
Correct |
168 ms |
22532 KB |
Output is correct |
28 |
Correct |
155 ms |
22488 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 |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
152 ms |
22556 KB |
Output is correct |
38 |
Correct |
1 ms |
300 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
178 ms |
22580 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
852 KB |
Output is correct |
45 |
Correct |
75 ms |
13660 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 |
300 KB |
Output is correct |
49 |
Correct |
42 ms |
6168 KB |
Output is correct |
50 |
Correct |
159 ms |
22560 KB |
Output is correct |
51 |
Correct |
158 ms |
22452 KB |
Output is correct |
52 |
Correct |
159 ms |
22596 KB |
Output is correct |
53 |
Correct |
69 ms |
13548 KB |
Output is correct |
54 |
Correct |
70 ms |
13544 KB |
Output is correct |
55 |
Correct |
164 ms |
22564 KB |
Output is correct |
56 |
Correct |
200 ms |
22532 KB |
Output is correct |
57 |
Correct |
68 ms |
13404 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
852 KB |
Output is correct |
61 |
Correct |
69 ms |
13500 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
39 ms |
6060 KB |
Output is correct |
66 |
Correct |
71 ms |
13424 KB |
Output is correct |
67 |
Correct |
70 ms |
13316 KB |
Output is correct |
68 |
Correct |
69 ms |
13388 KB |
Output is correct |
69 |
Correct |
69 ms |
13372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 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 |
304 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
160 ms |
22600 KB |
Output is correct |
8 |
Correct |
1 ms |
300 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 |
296 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
167 ms |
22480 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 |
796 KB |
Output is correct |
17 |
Correct |
82 ms |
13600 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
6104 KB |
Output is correct |
21 |
Correct |
190 ms |
22476 KB |
Output is correct |
22 |
Correct |
157 ms |
22544 KB |
Output is correct |
23 |
Correct |
206 ms |
22500 KB |
Output is correct |
24 |
Correct |
156 ms |
22464 KB |
Output is correct |
25 |
Correct |
76 ms |
13548 KB |
Output is correct |
26 |
Correct |
92 ms |
13532 KB |
Output is correct |
27 |
Correct |
168 ms |
22532 KB |
Output is correct |
28 |
Correct |
155 ms |
22488 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 |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
152 ms |
22556 KB |
Output is correct |
38 |
Correct |
1 ms |
300 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
178 ms |
22580 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
852 KB |
Output is correct |
45 |
Correct |
75 ms |
13660 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 |
300 KB |
Output is correct |
49 |
Correct |
42 ms |
6168 KB |
Output is correct |
50 |
Correct |
159 ms |
22560 KB |
Output is correct |
51 |
Correct |
158 ms |
22452 KB |
Output is correct |
52 |
Correct |
159 ms |
22596 KB |
Output is correct |
53 |
Correct |
69 ms |
13548 KB |
Output is correct |
54 |
Correct |
70 ms |
13544 KB |
Output is correct |
55 |
Correct |
164 ms |
22564 KB |
Output is correct |
56 |
Correct |
200 ms |
22532 KB |
Output is correct |
57 |
Correct |
68 ms |
13404 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 |
41 ms |
6056 KB |
Output is correct |
62 |
Correct |
159 ms |
22448 KB |
Output is correct |
63 |
Correct |
160 ms |
22468 KB |
Output is correct |
64 |
Correct |
158 ms |
22476 KB |
Output is correct |
65 |
Correct |
0 ms |
292 KB |
Output is correct |
66 |
Correct |
39 ms |
5976 KB |
Output is correct |
67 |
Correct |
161 ms |
22568 KB |
Output is correct |
68 |
Correct |
157 ms |
22420 KB |
Output is correct |
69 |
Correct |
158 ms |
22472 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
39 ms |
5936 KB |
Output is correct |
74 |
Correct |
159 ms |
22436 KB |
Output is correct |
75 |
Correct |
158 ms |
22348 KB |
Output is correct |
76 |
Correct |
158 ms |
22448 KB |
Output is correct |
77 |
Correct |
154 ms |
22356 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
3 ms |
852 KB |
Output is correct |
81 |
Correct |
69 ms |
13500 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
39 ms |
6060 KB |
Output is correct |
86 |
Correct |
71 ms |
13424 KB |
Output is correct |
87 |
Correct |
70 ms |
13316 KB |
Output is correct |
88 |
Correct |
69 ms |
13388 KB |
Output is correct |
89 |
Correct |
69 ms |
13372 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
292 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
71 ms |
13516 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
296 KB |
Output is correct |
97 |
Correct |
19 ms |
3504 KB |
Output is correct |
98 |
Correct |
71 ms |
13440 KB |
Output is correct |
99 |
Correct |
69 ms |
13368 KB |
Output is correct |
100 |
Correct |
69 ms |
13364 KB |
Output is correct |
101 |
Correct |
68 ms |
13368 KB |
Output is correct |
102 |
Correct |
62 ms |
13396 KB |
Output is correct |
103 |
Correct |
64 ms |
13336 KB |
Output is correct |
104 |
Correct |
64 ms |
13508 KB |
Output is correct |
105 |
Correct |
75 ms |
13364 KB |
Output is correct |