#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int construct(std::vector<std::vector<int>> p)
{
int N = p.size();
vi comp(N, -1);
vvi ans(N, vi(N, 0));
for (int v = 0; v < N; ++v)
{
if (comp[v] == -1)
{
vvi c(4);
comp[v] = v;
for (int u = 0; u < N; ++u)
{
if (p[v][u] == 0 || u == v)
continue;
if (comp[u] != -1)
return 0;
comp[u] = v;
c[p[v][u]].push_back(u);
}
if (sz(c[2]) && sz(c[3]))
return 0;
for (int u : c[1])
{
ans[v][u] = ans[u][v] = 1;
for (int w = 0; w < N; ++w)
if (comp[w] != comp[u] && p[u][w] > 0)
return 0;
for (int w : c[1])
if (p[u][w] != 1)
return 0;
for (int w : c[2])
if (p[u][w] != 2)
return 0;
for (int w : c[3])
if (p[u][w] != 3)
return 0;
}
if (!c[2].empty())
{
for (int u : c[2])
for (int w = 0; w < N; ++w)
if (comp[w] != comp[u] && p[u][w] > 0)
return 0;
vvi cycle;
vi C2(all(c[2]));
while (!C2.empty())
{
int u = C2.back();
C2.pop_back();
cycle.push_back({u});
int end = sz(C2);
for (int i = 0; i < end;)
{
int w = C2[i];
if (p[u][w] == 2)
++i;
else if (p[u][w] == 1)
{
cycle.back().push_back(w);
swap(C2[i], C2[--end]);
C2.pop_back();
}
}
}
// checks
if (sz(cycle) <= 1)
return 0;
for (int i = 0; i < sz(cycle); ++i)
{
for (int u : cycle[i])
for (int w : cycle[i])
if (p[u][w] != 1)
return 0;
for (int j = i + 1; j < sz(cycle); ++j)
for (int u : cycle[i])
for (int w : cycle[j])
if (p[u][w] != 2)
return 0;
}
// build
int last = v;
for (int i = 0; i < sz(cycle); ++i)
{
int u = cycle[i][0];
ans[last][u] = ans[u][last] = 1;
last = u;
for (int j = 1; j < sz(cycle[i]); ++j)
ans[u][cycle[i][j]] = ans[cycle[i][j]][u] = 1;
}
ans[last][v] = ans[v][last] = 1;
}
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
166 ms |
23896 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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
166 ms |
23896 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
300 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
156 ms |
23392 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
3 ms |
780 KB |
Output is correct |
17 |
Correct |
65 ms |
14028 KB |
Output is correct |
18 |
Correct |
0 ms |
304 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
37 ms |
6212 KB |
Output is correct |
21 |
Correct |
150 ms |
23920 KB |
Output is correct |
22 |
Correct |
151 ms |
23964 KB |
Output is correct |
23 |
Correct |
162 ms |
23948 KB |
Output is correct |
24 |
Correct |
158 ms |
23932 KB |
Output is correct |
25 |
Correct |
78 ms |
13956 KB |
Output is correct |
26 |
Correct |
61 ms |
13436 KB |
Output is correct |
27 |
Correct |
157 ms |
23452 KB |
Output is correct |
28 |
Correct |
152 ms |
23404 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1176 KB |
Output is correct |
9 |
Correct |
158 ms |
24012 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
7 ms |
1176 KB |
Output is correct |
13 |
Correct |
156 ms |
23936 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
66 ms |
14072 KB |
Output is correct |
18 |
Execution timed out |
1094 ms |
212 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
38 ms |
6212 KB |
Output is correct |
5 |
Correct |
157 ms |
24068 KB |
Output is correct |
6 |
Correct |
154 ms |
24012 KB |
Output is correct |
7 |
Correct |
157 ms |
23884 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
38 ms |
6248 KB |
Output is correct |
10 |
Correct |
152 ms |
23940 KB |
Output is correct |
11 |
Correct |
154 ms |
23936 KB |
Output is correct |
12 |
Correct |
156 ms |
23968 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 |
42 ms |
6228 KB |
Output is correct |
17 |
Correct |
158 ms |
23924 KB |
Output is correct |
18 |
Correct |
158 ms |
23924 KB |
Output is correct |
19 |
Correct |
152 ms |
23948 KB |
Output is correct |
20 |
Correct |
155 ms |
23940 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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
166 ms |
23896 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
300 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
156 ms |
23392 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
3 ms |
780 KB |
Output is correct |
17 |
Correct |
65 ms |
14028 KB |
Output is correct |
18 |
Correct |
0 ms |
304 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
37 ms |
6212 KB |
Output is correct |
21 |
Correct |
150 ms |
23920 KB |
Output is correct |
22 |
Correct |
151 ms |
23964 KB |
Output is correct |
23 |
Correct |
162 ms |
23948 KB |
Output is correct |
24 |
Correct |
158 ms |
23932 KB |
Output is correct |
25 |
Correct |
78 ms |
13956 KB |
Output is correct |
26 |
Correct |
61 ms |
13436 KB |
Output is correct |
27 |
Correct |
157 ms |
23452 KB |
Output is correct |
28 |
Correct |
152 ms |
23404 KB |
Output is correct |
29 |
Correct |
0 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 |
1 ms |
296 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1176 KB |
Output is correct |
37 |
Correct |
158 ms |
24012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
7 ms |
1176 KB |
Output is correct |
41 |
Correct |
156 ms |
23936 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
852 KB |
Output is correct |
45 |
Correct |
66 ms |
14072 KB |
Output is correct |
46 |
Execution timed out |
1094 ms |
212 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
166 ms |
23896 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
300 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
156 ms |
23392 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
3 ms |
780 KB |
Output is correct |
17 |
Correct |
65 ms |
14028 KB |
Output is correct |
18 |
Correct |
0 ms |
304 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
37 ms |
6212 KB |
Output is correct |
21 |
Correct |
150 ms |
23920 KB |
Output is correct |
22 |
Correct |
151 ms |
23964 KB |
Output is correct |
23 |
Correct |
162 ms |
23948 KB |
Output is correct |
24 |
Correct |
158 ms |
23932 KB |
Output is correct |
25 |
Correct |
78 ms |
13956 KB |
Output is correct |
26 |
Correct |
61 ms |
13436 KB |
Output is correct |
27 |
Correct |
157 ms |
23452 KB |
Output is correct |
28 |
Correct |
152 ms |
23404 KB |
Output is correct |
29 |
Correct |
0 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 |
1 ms |
296 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1176 KB |
Output is correct |
37 |
Correct |
158 ms |
24012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
7 ms |
1176 KB |
Output is correct |
41 |
Correct |
156 ms |
23936 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
852 KB |
Output is correct |
45 |
Correct |
66 ms |
14072 KB |
Output is correct |
46 |
Execution timed out |
1094 ms |
212 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |