#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> ans(0);
vector<vector<int>> haha(0);
vector<bool> bruh(3001,true);
int n;
vector<int> col(3000,-1);
vector<int> no(3000,-1);
void dfs(int a, int c) {
col[a] = c;
if(a != c) {
ans[a][c] = 1;
ans[c][a] = 1;
}
for(int i = 0; i < n; i++) {
if(col[i] == -1 && haha[a][i] == 1) {
dfs(i,c);
}
}
}
int construct(vector<vector<int>> p) {
n = p[0].size();
haha = p;
vector<int> wut(0);
for(int i = 0; i < n; i++) {
ans.push_back(vector<int> (n));
}
for(int i = 0; i < n; i++) {
if(col[i] == -1) {
dfs(i,i);
wut.push_back(i);
}
}
for(int i = 0; i < wut.size(); i++) {
if(no[wut[i]] == -1) {
vector<int> wow(0);
wow.push_back(wut[i]);
no[wut[i]] = i;
for(int j = 0; j < wut.size(); j++) {
if(haha[wut[i]][wut[j]] == 2 && no[wut[j]] == -1) {
bruh[j] = false;
wow.push_back(wut[j]);
no[wut[j]] = i;
}
}
if(wow.size() == 2) {
return 0;
}
if(wow.size() > 1) {
for(int j = 0; j < wow.size(); j++) {
ans[wow[j]][wow[(j+1)%(int)wow.size()]] = 1;
ans[wow[(j+1)%(int)wow.size()]][wow[j]] = 1;
}
}
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i != j) {
if((col[i] == col[j]) && haha[i][j] != 1) {
return 0;
}
if((col[i] != col[j] && no[col[i]] == no[col[j]]) && haha[i][j] != 2) {
return 0;
}
if(no[col[i]] != no[col[j]] && haha[i][j] != 0) {
return 0;
}
}
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < wut.size(); i++) {
| ~~^~~~~~~~~~~~
supertrees.cpp:44:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int j = 0; j < wut.size(); j++) {
| ~~^~~~~~~~~~~~
supertrees.cpp:55:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int j = 0; j < wow.size(); j++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1364 KB |
Output is correct |
7 |
Correct |
145 ms |
26012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1364 KB |
Output is correct |
7 |
Correct |
145 ms |
26012 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
244 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1364 KB |
Output is correct |
13 |
Correct |
147 ms |
26072 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
62 ms |
16076 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
36 ms |
6768 KB |
Output is correct |
21 |
Correct |
153 ms |
26024 KB |
Output is correct |
22 |
Correct |
146 ms |
26016 KB |
Output is correct |
23 |
Correct |
151 ms |
25980 KB |
Output is correct |
24 |
Correct |
144 ms |
26008 KB |
Output is correct |
25 |
Correct |
60 ms |
16040 KB |
Output is correct |
26 |
Correct |
58 ms |
16116 KB |
Output is correct |
27 |
Correct |
149 ms |
25976 KB |
Output is correct |
28 |
Correct |
180 ms |
25932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
1364 KB |
Output is correct |
9 |
Correct |
149 ms |
26012 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 |
1312 KB |
Output is correct |
13 |
Correct |
145 ms |
25920 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 |
852 KB |
Output is correct |
17 |
Correct |
62 ms |
16024 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
37 ms |
6692 KB |
Output is correct |
22 |
Correct |
175 ms |
26024 KB |
Output is correct |
23 |
Correct |
156 ms |
26012 KB |
Output is correct |
24 |
Correct |
149 ms |
26032 KB |
Output is correct |
25 |
Correct |
58 ms |
16032 KB |
Output is correct |
26 |
Correct |
58 ms |
16032 KB |
Output is correct |
27 |
Correct |
153 ms |
26024 KB |
Output is correct |
28 |
Correct |
147 ms |
26020 KB |
Output is correct |
29 |
Correct |
60 ms |
16024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
37 ms |
6756 KB |
Output is correct |
5 |
Correct |
148 ms |
26020 KB |
Output is correct |
6 |
Correct |
149 ms |
25936 KB |
Output is correct |
7 |
Correct |
151 ms |
26188 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
37 ms |
6700 KB |
Output is correct |
10 |
Correct |
163 ms |
26016 KB |
Output is correct |
11 |
Correct |
152 ms |
25984 KB |
Output is correct |
12 |
Correct |
149 ms |
25972 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
44 ms |
6688 KB |
Output is correct |
17 |
Correct |
156 ms |
26020 KB |
Output is correct |
18 |
Correct |
145 ms |
26020 KB |
Output is correct |
19 |
Correct |
154 ms |
26000 KB |
Output is correct |
20 |
Correct |
147 ms |
26028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1364 KB |
Output is correct |
7 |
Correct |
145 ms |
26012 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
244 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1364 KB |
Output is correct |
13 |
Correct |
147 ms |
26072 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
62 ms |
16076 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
36 ms |
6768 KB |
Output is correct |
21 |
Correct |
153 ms |
26024 KB |
Output is correct |
22 |
Correct |
146 ms |
26016 KB |
Output is correct |
23 |
Correct |
151 ms |
25980 KB |
Output is correct |
24 |
Correct |
144 ms |
26008 KB |
Output is correct |
25 |
Correct |
60 ms |
16040 KB |
Output is correct |
26 |
Correct |
58 ms |
16116 KB |
Output is correct |
27 |
Correct |
149 ms |
25976 KB |
Output is correct |
28 |
Correct |
180 ms |
25932 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 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 |
6 ms |
1364 KB |
Output is correct |
37 |
Correct |
149 ms |
26012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1312 KB |
Output is correct |
41 |
Correct |
145 ms |
25920 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
62 ms |
16024 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
37 ms |
6692 KB |
Output is correct |
50 |
Correct |
175 ms |
26024 KB |
Output is correct |
51 |
Correct |
156 ms |
26012 KB |
Output is correct |
52 |
Correct |
149 ms |
26032 KB |
Output is correct |
53 |
Correct |
58 ms |
16032 KB |
Output is correct |
54 |
Correct |
58 ms |
16032 KB |
Output is correct |
55 |
Correct |
153 ms |
26024 KB |
Output is correct |
56 |
Correct |
147 ms |
26020 KB |
Output is correct |
57 |
Correct |
60 ms |
16024 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 |
980 KB |
Output is correct |
61 |
Correct |
63 ms |
18068 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
256 KB |
Output is correct |
65 |
Correct |
38 ms |
7264 KB |
Output is correct |
66 |
Correct |
61 ms |
18076 KB |
Output is correct |
67 |
Correct |
60 ms |
18072 KB |
Output is correct |
68 |
Correct |
59 ms |
18060 KB |
Output is correct |
69 |
Correct |
59 ms |
17960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1364 KB |
Output is correct |
7 |
Correct |
145 ms |
26012 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
244 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1364 KB |
Output is correct |
13 |
Correct |
147 ms |
26072 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
62 ms |
16076 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
36 ms |
6768 KB |
Output is correct |
21 |
Correct |
153 ms |
26024 KB |
Output is correct |
22 |
Correct |
146 ms |
26016 KB |
Output is correct |
23 |
Correct |
151 ms |
25980 KB |
Output is correct |
24 |
Correct |
144 ms |
26008 KB |
Output is correct |
25 |
Correct |
60 ms |
16040 KB |
Output is correct |
26 |
Correct |
58 ms |
16116 KB |
Output is correct |
27 |
Correct |
149 ms |
25976 KB |
Output is correct |
28 |
Correct |
180 ms |
25932 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 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 |
6 ms |
1364 KB |
Output is correct |
37 |
Correct |
149 ms |
26012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1312 KB |
Output is correct |
41 |
Correct |
145 ms |
25920 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
62 ms |
16024 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
37 ms |
6692 KB |
Output is correct |
50 |
Correct |
175 ms |
26024 KB |
Output is correct |
51 |
Correct |
156 ms |
26012 KB |
Output is correct |
52 |
Correct |
149 ms |
26032 KB |
Output is correct |
53 |
Correct |
58 ms |
16032 KB |
Output is correct |
54 |
Correct |
58 ms |
16032 KB |
Output is correct |
55 |
Correct |
153 ms |
26024 KB |
Output is correct |
56 |
Correct |
147 ms |
26020 KB |
Output is correct |
57 |
Correct |
60 ms |
16024 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
37 ms |
6756 KB |
Output is correct |
62 |
Correct |
148 ms |
26020 KB |
Output is correct |
63 |
Correct |
149 ms |
25936 KB |
Output is correct |
64 |
Correct |
151 ms |
26188 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
37 ms |
6700 KB |
Output is correct |
67 |
Correct |
163 ms |
26016 KB |
Output is correct |
68 |
Correct |
152 ms |
25984 KB |
Output is correct |
69 |
Correct |
149 ms |
25972 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
44 ms |
6688 KB |
Output is correct |
74 |
Correct |
156 ms |
26020 KB |
Output is correct |
75 |
Correct |
145 ms |
26020 KB |
Output is correct |
76 |
Correct |
154 ms |
26000 KB |
Output is correct |
77 |
Correct |
147 ms |
26028 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 |
980 KB |
Output is correct |
81 |
Correct |
63 ms |
18068 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
256 KB |
Output is correct |
85 |
Correct |
38 ms |
7264 KB |
Output is correct |
86 |
Correct |
61 ms |
18076 KB |
Output is correct |
87 |
Correct |
60 ms |
18072 KB |
Output is correct |
88 |
Correct |
59 ms |
18060 KB |
Output is correct |
89 |
Correct |
59 ms |
17960 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
948 KB |
Output is correct |
93 |
Correct |
62 ms |
18060 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 |
15 ms |
4760 KB |
Output is correct |
98 |
Correct |
60 ms |
18068 KB |
Output is correct |
99 |
Correct |
59 ms |
18076 KB |
Output is correct |
100 |
Correct |
59 ms |
18060 KB |
Output is correct |
101 |
Correct |
60 ms |
18076 KB |
Output is correct |
102 |
Correct |
63 ms |
18060 KB |
Output is correct |
103 |
Correct |
59 ms |
18060 KB |
Output is correct |
104 |
Correct |
58 ms |
18076 KB |
Output is correct |
105 |
Correct |
74 ms |
18056 KB |
Output is correct |