#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
376 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
148 ms |
24108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
376 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
148 ms |
24108 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1184 KB |
Output is correct |
13 |
Correct |
151 ms |
23896 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
872 KB |
Output is correct |
17 |
Correct |
72 ms |
14196 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
6168 KB |
Output is correct |
21 |
Correct |
150 ms |
24056 KB |
Output is correct |
22 |
Correct |
161 ms |
24056 KB |
Output is correct |
23 |
Correct |
154 ms |
24020 KB |
Output is correct |
24 |
Correct |
154 ms |
23924 KB |
Output is correct |
25 |
Correct |
69 ms |
14160 KB |
Output is correct |
26 |
Correct |
77 ms |
14324 KB |
Output is correct |
27 |
Correct |
154 ms |
24068 KB |
Output is correct |
28 |
Correct |
152 ms |
24148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
1368 KB |
Output is correct |
9 |
Correct |
151 ms |
24072 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
147 ms |
24056 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
72 ms |
14220 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
440 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
41 ms |
6552 KB |
Output is correct |
22 |
Correct |
157 ms |
23932 KB |
Output is correct |
23 |
Correct |
168 ms |
23944 KB |
Output is correct |
24 |
Correct |
166 ms |
24012 KB |
Output is correct |
25 |
Correct |
66 ms |
14072 KB |
Output is correct |
26 |
Correct |
70 ms |
14084 KB |
Output is correct |
27 |
Correct |
164 ms |
24144 KB |
Output is correct |
28 |
Correct |
155 ms |
24148 KB |
Output is correct |
29 |
Correct |
72 ms |
14200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
39 ms |
6228 KB |
Output is correct |
5 |
Correct |
151 ms |
24144 KB |
Output is correct |
6 |
Correct |
161 ms |
24072 KB |
Output is correct |
7 |
Correct |
154 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
39 ms |
6172 KB |
Output is correct |
10 |
Correct |
149 ms |
24092 KB |
Output is correct |
11 |
Correct |
183 ms |
24144 KB |
Output is correct |
12 |
Correct |
153 ms |
24148 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
39 ms |
6236 KB |
Output is correct |
17 |
Correct |
154 ms |
24148 KB |
Output is correct |
18 |
Correct |
152 ms |
23920 KB |
Output is correct |
19 |
Correct |
151 ms |
23976 KB |
Output is correct |
20 |
Correct |
153 ms |
23892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
376 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
148 ms |
24108 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1184 KB |
Output is correct |
13 |
Correct |
151 ms |
23896 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
872 KB |
Output is correct |
17 |
Correct |
72 ms |
14196 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
6168 KB |
Output is correct |
21 |
Correct |
150 ms |
24056 KB |
Output is correct |
22 |
Correct |
161 ms |
24056 KB |
Output is correct |
23 |
Correct |
154 ms |
24020 KB |
Output is correct |
24 |
Correct |
154 ms |
23924 KB |
Output is correct |
25 |
Correct |
69 ms |
14160 KB |
Output is correct |
26 |
Correct |
77 ms |
14324 KB |
Output is correct |
27 |
Correct |
154 ms |
24068 KB |
Output is correct |
28 |
Correct |
152 ms |
24148 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
440 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
432 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
8 ms |
1368 KB |
Output is correct |
37 |
Correct |
151 ms |
24072 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
147 ms |
24056 KB |
Output is correct |
42 |
Correct |
1 ms |
504 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
72 ms |
14220 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
440 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
41 ms |
6552 KB |
Output is correct |
50 |
Correct |
157 ms |
23932 KB |
Output is correct |
51 |
Correct |
168 ms |
23944 KB |
Output is correct |
52 |
Correct |
166 ms |
24012 KB |
Output is correct |
53 |
Correct |
66 ms |
14072 KB |
Output is correct |
54 |
Correct |
70 ms |
14084 KB |
Output is correct |
55 |
Correct |
164 ms |
24144 KB |
Output is correct |
56 |
Correct |
155 ms |
24148 KB |
Output is correct |
57 |
Correct |
72 ms |
14200 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
67 ms |
14092 KB |
Output is correct |
62 |
Correct |
1 ms |
344 KB |
Output is correct |
63 |
Correct |
1 ms |
344 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
39 ms |
6212 KB |
Output is correct |
66 |
Correct |
69 ms |
14216 KB |
Output is correct |
67 |
Correct |
67 ms |
14080 KB |
Output is correct |
68 |
Correct |
74 ms |
14344 KB |
Output is correct |
69 |
Correct |
65 ms |
14164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
376 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
148 ms |
24108 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1184 KB |
Output is correct |
13 |
Correct |
151 ms |
23896 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
872 KB |
Output is correct |
17 |
Correct |
72 ms |
14196 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
6168 KB |
Output is correct |
21 |
Correct |
150 ms |
24056 KB |
Output is correct |
22 |
Correct |
161 ms |
24056 KB |
Output is correct |
23 |
Correct |
154 ms |
24020 KB |
Output is correct |
24 |
Correct |
154 ms |
23924 KB |
Output is correct |
25 |
Correct |
69 ms |
14160 KB |
Output is correct |
26 |
Correct |
77 ms |
14324 KB |
Output is correct |
27 |
Correct |
154 ms |
24068 KB |
Output is correct |
28 |
Correct |
152 ms |
24148 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
440 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
432 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
8 ms |
1368 KB |
Output is correct |
37 |
Correct |
151 ms |
24072 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
147 ms |
24056 KB |
Output is correct |
42 |
Correct |
1 ms |
504 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
72 ms |
14220 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
440 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
41 ms |
6552 KB |
Output is correct |
50 |
Correct |
157 ms |
23932 KB |
Output is correct |
51 |
Correct |
168 ms |
23944 KB |
Output is correct |
52 |
Correct |
166 ms |
24012 KB |
Output is correct |
53 |
Correct |
66 ms |
14072 KB |
Output is correct |
54 |
Correct |
70 ms |
14084 KB |
Output is correct |
55 |
Correct |
164 ms |
24144 KB |
Output is correct |
56 |
Correct |
155 ms |
24148 KB |
Output is correct |
57 |
Correct |
72 ms |
14200 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
39 ms |
6228 KB |
Output is correct |
62 |
Correct |
151 ms |
24144 KB |
Output is correct |
63 |
Correct |
161 ms |
24072 KB |
Output is correct |
64 |
Correct |
154 ms |
24148 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
39 ms |
6172 KB |
Output is correct |
67 |
Correct |
149 ms |
24092 KB |
Output is correct |
68 |
Correct |
183 ms |
24144 KB |
Output is correct |
69 |
Correct |
153 ms |
24148 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
39 ms |
6236 KB |
Output is correct |
74 |
Correct |
154 ms |
24148 KB |
Output is correct |
75 |
Correct |
152 ms |
23920 KB |
Output is correct |
76 |
Correct |
151 ms |
23976 KB |
Output is correct |
77 |
Correct |
153 ms |
23892 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
860 KB |
Output is correct |
81 |
Correct |
67 ms |
14092 KB |
Output is correct |
82 |
Correct |
1 ms |
344 KB |
Output is correct |
83 |
Correct |
1 ms |
344 KB |
Output is correct |
84 |
Correct |
1 ms |
348 KB |
Output is correct |
85 |
Correct |
39 ms |
6212 KB |
Output is correct |
86 |
Correct |
69 ms |
14216 KB |
Output is correct |
87 |
Correct |
67 ms |
14080 KB |
Output is correct |
88 |
Correct |
74 ms |
14344 KB |
Output is correct |
89 |
Correct |
65 ms |
14164 KB |
Output is correct |
90 |
Correct |
0 ms |
344 KB |
Output is correct |
91 |
Correct |
0 ms |
344 KB |
Output is correct |
92 |
Correct |
3 ms |
860 KB |
Output is correct |
93 |
Correct |
70 ms |
14216 KB |
Output is correct |
94 |
Correct |
0 ms |
344 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Correct |
18 ms |
3704 KB |
Output is correct |
98 |
Correct |
65 ms |
14204 KB |
Output is correct |
99 |
Correct |
65 ms |
14164 KB |
Output is correct |
100 |
Correct |
68 ms |
14080 KB |
Output is correct |
101 |
Correct |
68 ms |
14212 KB |
Output is correct |
102 |
Correct |
61 ms |
14416 KB |
Output is correct |
103 |
Correct |
62 ms |
14204 KB |
Output is correct |
104 |
Correct |
72 ms |
14256 KB |
Output is correct |
105 |
Correct |
78 ms |
14216 KB |
Output is correct |