#include "supertrees.h"
#include <iostream>
#include <map>
#include <vector>
using namespace std;
vector<int> v1[1005], v2[1005];
int color1[1005], color2[1005], c1 = 1, c2 = 1;
int sk[1005], qan[1005], vr[1005], anc1[1005], anc2[1005];
int ska[1005], vra[1005], ogt[1005], ogtdfs[1005];
void Dfs1(int g)
{
color1[g] = c1;
for (auto to: v1[g])
{
if (color1[to] == 0)
{
Dfs1(to);
}
}
}
void Dfs2(int g)
{
color2[g] = c2;
ogtdfs[color1[g]] = 1;
for (auto to : v2[g])
{
if (color2[to] == 0 && ogtdfs[color1[to]] == 0)
{
Dfs2(to);
}
}
}
int construct(vector<vector<int>> x)
{
int n = x.size(), i, j, st = 1;
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
if (i == j)
continue;
if (x[i][j] == 3)
return 0;
else if (x[i][j] == 2)
v2[i].push_back(j);
else if (x[i][j] == 1)
v1[i].push_back(j);
}
}
for ( i = 0; i < n; i++)
{
if (color1[i] == 0)
{
Dfs1(i);
c1++;
}
}
for ( i = 0; i < n; i++)
{
if (color2[i] == 0)
{
Dfs2(i);
c2++;
}
}
for (i = 0; i <= n; i++)
{
sk[i] = -1;
anc1[i] = -1;
anc2[i] = -1;
}
for ( i = 0; i < n; i++)
{
if (sk[color2[i]] == -1)
sk[color2[i]] = i;
vr[color2[i]] = i;
qan[color2[i]]++;
}
for ( i = 0; i <= n; i++)
{
if (qan[color2[i]] == 2)
return 0;
}
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
if (i == j)continue;
if (color1[i] == color1[j] && x[i][j] == 2)
return 0;
if ((color1[i] == color1[j] || color2[i] == color2[j]) && x[i][j] == 0)
return 0;
}
}
vector<vector<int>> ans(n, vector<int>(n, 0));
for ( i = 0; i < n; i++)
{
if (anc1[color1[i]] == -1)
anc1[color1[i]] = i;
else
{
ans[i][anc1[color1[i]]] = 1;
ans[anc1[color1[i]]][i] = 1;
anc1[color1[i]] = i;
}
if (anc2[color2[i]] == -1)
{
anc2[color2[i]] = i;
ska[color2[i]] = i;
}
else if(ogt[color1[i]] == 0)
{
ans[i][anc2[color2[i]]] = 1;
ans[anc2[color2[i]]][i] = 1;
anc2[color2[i]] = i;
vra[color2[i]] = i;
}
}
for ( i = 0; i <= n; i++)
{
if (qan[i] > 2)
{
ans[ska[i]][vra[i]] = 1;
ans[vra[i]][ska[i]] = 1;
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:38:26: warning: unused variable 'st' [-Wunused-variable]
38 | int n = x.size(), i, j, st = 1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1420 KB |
Output is correct |
7 |
Correct |
164 ms |
26168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1420 KB |
Output is correct |
7 |
Correct |
164 ms |
26168 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
448 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1276 KB |
Output is correct |
13 |
Correct |
161 ms |
22072 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
83 ms |
10676 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
43 ms |
5844 KB |
Output is correct |
21 |
Correct |
169 ms |
22620 KB |
Output is correct |
22 |
Correct |
160 ms |
22112 KB |
Output is correct |
23 |
Correct |
173 ms |
24120 KB |
Output is correct |
24 |
Correct |
165 ms |
22080 KB |
Output is correct |
25 |
Correct |
71 ms |
8772 KB |
Output is correct |
26 |
Correct |
63 ms |
8268 KB |
Output is correct |
27 |
Correct |
174 ms |
25152 KB |
Output is correct |
28 |
Correct |
173 ms |
22064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
161 ms |
22080 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1416 KB |
Output is correct |
13 |
Correct |
166 ms |
26168 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
75 ms |
10696 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 |
45 ms |
5816 KB |
Output is correct |
22 |
Correct |
163 ms |
24488 KB |
Output is correct |
23 |
Correct |
167 ms |
24100 KB |
Output is correct |
24 |
Correct |
175 ms |
27048 KB |
Output is correct |
25 |
Correct |
69 ms |
10164 KB |
Output is correct |
26 |
Correct |
66 ms |
10664 KB |
Output is correct |
27 |
Correct |
162 ms |
24112 KB |
Output is correct |
28 |
Correct |
179 ms |
26024 KB |
Output is correct |
29 |
Correct |
68 ms |
10156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
41 ms |
5836 KB |
Output is correct |
5 |
Correct |
168 ms |
22632 KB |
Output is correct |
6 |
Correct |
158 ms |
22072 KB |
Output is correct |
7 |
Correct |
172 ms |
24140 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
41 ms |
5876 KB |
Output is correct |
10 |
Correct |
164 ms |
24496 KB |
Output is correct |
11 |
Correct |
168 ms |
24104 KB |
Output is correct |
12 |
Correct |
175 ms |
27060 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
42 ms |
6300 KB |
Output is correct |
17 |
Correct |
164 ms |
24496 KB |
Output is correct |
18 |
Correct |
172 ms |
24604 KB |
Output is correct |
19 |
Correct |
161 ms |
24208 KB |
Output is correct |
20 |
Correct |
162 ms |
23984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1420 KB |
Output is correct |
7 |
Correct |
164 ms |
26168 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
448 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1276 KB |
Output is correct |
13 |
Correct |
161 ms |
22072 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
83 ms |
10676 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
43 ms |
5844 KB |
Output is correct |
21 |
Correct |
169 ms |
22620 KB |
Output is correct |
22 |
Correct |
160 ms |
22112 KB |
Output is correct |
23 |
Correct |
173 ms |
24120 KB |
Output is correct |
24 |
Correct |
165 ms |
22080 KB |
Output is correct |
25 |
Correct |
71 ms |
8772 KB |
Output is correct |
26 |
Correct |
63 ms |
8268 KB |
Output is correct |
27 |
Correct |
174 ms |
25152 KB |
Output is correct |
28 |
Correct |
173 ms |
22064 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
161 ms |
22080 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1416 KB |
Output is correct |
41 |
Correct |
166 ms |
26168 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
75 ms |
10696 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 |
45 ms |
5816 KB |
Output is correct |
50 |
Correct |
163 ms |
24488 KB |
Output is correct |
51 |
Correct |
167 ms |
24100 KB |
Output is correct |
52 |
Correct |
175 ms |
27048 KB |
Output is correct |
53 |
Correct |
69 ms |
10164 KB |
Output is correct |
54 |
Correct |
66 ms |
10664 KB |
Output is correct |
55 |
Correct |
162 ms |
24112 KB |
Output is correct |
56 |
Correct |
179 ms |
26024 KB |
Output is correct |
57 |
Correct |
68 ms |
10156 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
4 ms |
880 KB |
Output is correct |
61 |
Correct |
83 ms |
14260 KB |
Output is correct |
62 |
Correct |
0 ms |
340 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
356 KB |
Output is correct |
65 |
Correct |
42 ms |
6340 KB |
Output is correct |
66 |
Correct |
73 ms |
10788 KB |
Output is correct |
67 |
Correct |
69 ms |
10700 KB |
Output is correct |
68 |
Correct |
65 ms |
10420 KB |
Output is correct |
69 |
Correct |
65 ms |
10156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1420 KB |
Output is correct |
7 |
Correct |
164 ms |
26168 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
448 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1276 KB |
Output is correct |
13 |
Correct |
161 ms |
22072 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
83 ms |
10676 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
43 ms |
5844 KB |
Output is correct |
21 |
Correct |
169 ms |
22620 KB |
Output is correct |
22 |
Correct |
160 ms |
22112 KB |
Output is correct |
23 |
Correct |
173 ms |
24120 KB |
Output is correct |
24 |
Correct |
165 ms |
22080 KB |
Output is correct |
25 |
Correct |
71 ms |
8772 KB |
Output is correct |
26 |
Correct |
63 ms |
8268 KB |
Output is correct |
27 |
Correct |
174 ms |
25152 KB |
Output is correct |
28 |
Correct |
173 ms |
22064 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
161 ms |
22080 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1416 KB |
Output is correct |
41 |
Correct |
166 ms |
26168 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
75 ms |
10696 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 |
45 ms |
5816 KB |
Output is correct |
50 |
Correct |
163 ms |
24488 KB |
Output is correct |
51 |
Correct |
167 ms |
24100 KB |
Output is correct |
52 |
Correct |
175 ms |
27048 KB |
Output is correct |
53 |
Correct |
69 ms |
10164 KB |
Output is correct |
54 |
Correct |
66 ms |
10664 KB |
Output is correct |
55 |
Correct |
162 ms |
24112 KB |
Output is correct |
56 |
Correct |
179 ms |
26024 KB |
Output is correct |
57 |
Correct |
68 ms |
10156 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
41 ms |
5836 KB |
Output is correct |
62 |
Correct |
168 ms |
22632 KB |
Output is correct |
63 |
Correct |
158 ms |
22072 KB |
Output is correct |
64 |
Correct |
172 ms |
24140 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
41 ms |
5876 KB |
Output is correct |
67 |
Correct |
164 ms |
24496 KB |
Output is correct |
68 |
Correct |
168 ms |
24104 KB |
Output is correct |
69 |
Correct |
175 ms |
27060 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
42 ms |
6300 KB |
Output is correct |
74 |
Correct |
164 ms |
24496 KB |
Output is correct |
75 |
Correct |
172 ms |
24604 KB |
Output is correct |
76 |
Correct |
161 ms |
24208 KB |
Output is correct |
77 |
Correct |
162 ms |
23984 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
4 ms |
880 KB |
Output is correct |
81 |
Correct |
83 ms |
14260 KB |
Output is correct |
82 |
Correct |
0 ms |
340 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
356 KB |
Output is correct |
85 |
Correct |
42 ms |
6340 KB |
Output is correct |
86 |
Correct |
73 ms |
10788 KB |
Output is correct |
87 |
Correct |
69 ms |
10700 KB |
Output is correct |
88 |
Correct |
65 ms |
10420 KB |
Output is correct |
89 |
Correct |
65 ms |
10156 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
0 ms |
340 KB |
Output is correct |
92 |
Correct |
3 ms |
724 KB |
Output is correct |
93 |
Correct |
65 ms |
10080 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
340 KB |
Output is correct |
96 |
Correct |
0 ms |
352 KB |
Output is correct |
97 |
Correct |
17 ms |
2736 KB |
Output is correct |
98 |
Correct |
65 ms |
10188 KB |
Output is correct |
99 |
Correct |
71 ms |
10148 KB |
Output is correct |
100 |
Correct |
63 ms |
10188 KB |
Output is correct |
101 |
Correct |
61 ms |
10152 KB |
Output is correct |
102 |
Correct |
62 ms |
10212 KB |
Output is correct |
103 |
Correct |
61 ms |
10152 KB |
Output is correct |
104 |
Correct |
61 ms |
10060 KB |
Output is correct |
105 |
Correct |
69 ms |
10152 KB |
Output is correct |