#include "supertrees.h"
#include <vector>
#include <iostream>
using namespace std;
bool obd[20005];
bool obd3[20005];
int dis[20005];
int tip[20005];
vector<int> el[20005];
int par(int x)
{
return dis[x] = (dis[x] == x ? x : par(dis[x]));
}
void zd(int x, int y, bool zlij = true)
{
x = par(x);
y = par(y);
if (x == y)
return;
if (el[x].size() < el[y].size())
swap(x, y);
if (zlij)
{
if (el[x].empty())
el[x].push_back(x);
if (el[y].empty())
el[y].push_back(y);
for (auto e : el[y])
el[x].push_back(e);
}
dis[y] = x;
return;
}
int construct(vector<vector<int>> p)
{
int n = p.size();
vector<vector<int>> gr(n, vector<int>(n, 0));
for (int i = 0; i <= n; i++)
dis[i] = i;
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++)
{
if (p[i][j] == 1 && par(i)-par(j))
{
gr[par(i)][par(j)] = gr[par(j)][par(i)] = 1;
zd(i, j, 0);
}
}
int dalje2 = 0;
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++)
{
if (p[i][j] == 2 && par(i)-par(j))
{
tip[i] = tip[j] = 2;
dalje2 = 1;
zd(i, j);
}
}
if (dalje2)
{
for (int i = 0; i < n; i++)
{
int x = par(i);
if (obd[x] || tip[x] != 2)
continue;
obd[x] = 1;
vector<int> tr = el[x];
if (tr.size() <= 2)
return 0;
tr.push_back(x);
int pr = -1;
for (auto v : tr)
{
if (pr+1)
gr[v][pr] = gr[pr][v] = 1;
pr = v;
}
}
}
int dalje3 = 0;
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++)
{
if (p[i][j] == 3)
{
if (tip[i] == 2 || tip[j] == 2)
return 0;
// cout << i << " " << j << " " << tip[i] << " " << tip[j] << "\n";
tip[i] = tip[j] = 3;
dalje3 = 1;
zd(i, j);
}
}
if (dalje3)
{
for (int i = 0; i < n; i++)
{
int x = par(i);
if (obd3[x] || tip[x] != 3)
continue;
obd3[x] = 1;
vector<int> tr = el[x];
if (tr.size() <= 3)
return 0;
tr.push_back(x);
int pr = -1;
for (auto v : tr)
{
if (pr+1)
gr[v][pr] = gr[pr][v] = 1;
pr = v;
}
gr[x][tr[2]] = gr[tr[2]][x] = 1;
}
}
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++)
{
if (p[i][j] == 0 && par(i) == par(j))
return 0;
if (p[i][j] && par(i) != par(j))
return 0;
if (p[i][j] && tip[i] && tip[j] && tip[i] != tip[j])
return 0;
}
build(gr);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
4 |
Correct |
0 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
860 KB |
Output is correct |
6 |
Correct |
9 ms |
1884 KB |
Output is correct |
7 |
Correct |
168 ms |
22444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
4 |
Correct |
0 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
860 KB |
Output is correct |
6 |
Correct |
9 ms |
1884 KB |
Output is correct |
7 |
Correct |
168 ms |
22444 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
1624 KB |
Output is correct |
13 |
Correct |
166 ms |
22448 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
0 ms |
860 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
82 ms |
12628 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
41 ms |
6288 KB |
Output is correct |
21 |
Correct |
164 ms |
22608 KB |
Output is correct |
22 |
Correct |
165 ms |
22608 KB |
Output is correct |
23 |
Correct |
209 ms |
22556 KB |
Output is correct |
24 |
Correct |
162 ms |
22612 KB |
Output is correct |
25 |
Correct |
71 ms |
12628 KB |
Output is correct |
26 |
Correct |
72 ms |
12624 KB |
Output is correct |
27 |
Correct |
172 ms |
22636 KB |
Output is correct |
28 |
Correct |
165 ms |
22608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
860 KB |
Output is correct |
8 |
Correct |
7 ms |
1784 KB |
Output is correct |
9 |
Correct |
168 ms |
22640 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
8 ms |
1628 KB |
Output is correct |
13 |
Correct |
165 ms |
22500 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
1 ms |
856 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
80 ms |
12788 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
19 |
Correct |
0 ms |
860 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
44 ms |
6328 KB |
Output is correct |
22 |
Correct |
170 ms |
22676 KB |
Output is correct |
23 |
Correct |
164 ms |
22612 KB |
Output is correct |
24 |
Correct |
178 ms |
22684 KB |
Output is correct |
25 |
Correct |
70 ms |
12628 KB |
Output is correct |
26 |
Correct |
72 ms |
12624 KB |
Output is correct |
27 |
Correct |
165 ms |
22516 KB |
Output is correct |
28 |
Correct |
173 ms |
22612 KB |
Output is correct |
29 |
Correct |
71 ms |
12532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
41 ms |
6232 KB |
Output is correct |
5 |
Correct |
165 ms |
22512 KB |
Output is correct |
6 |
Correct |
168 ms |
22500 KB |
Output is correct |
7 |
Correct |
172 ms |
22612 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
41 ms |
6236 KB |
Output is correct |
10 |
Correct |
166 ms |
22552 KB |
Output is correct |
11 |
Correct |
186 ms |
22516 KB |
Output is correct |
12 |
Correct |
177 ms |
22528 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
16 |
Correct |
41 ms |
6172 KB |
Output is correct |
17 |
Correct |
165 ms |
22500 KB |
Output is correct |
18 |
Correct |
178 ms |
22516 KB |
Output is correct |
19 |
Correct |
163 ms |
22612 KB |
Output is correct |
20 |
Correct |
163 ms |
22500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
4 |
Correct |
0 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
860 KB |
Output is correct |
6 |
Correct |
9 ms |
1884 KB |
Output is correct |
7 |
Correct |
168 ms |
22444 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
1624 KB |
Output is correct |
13 |
Correct |
166 ms |
22448 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
0 ms |
860 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
82 ms |
12628 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
41 ms |
6288 KB |
Output is correct |
21 |
Correct |
164 ms |
22608 KB |
Output is correct |
22 |
Correct |
165 ms |
22608 KB |
Output is correct |
23 |
Correct |
209 ms |
22556 KB |
Output is correct |
24 |
Correct |
162 ms |
22612 KB |
Output is correct |
25 |
Correct |
71 ms |
12628 KB |
Output is correct |
26 |
Correct |
72 ms |
12624 KB |
Output is correct |
27 |
Correct |
172 ms |
22636 KB |
Output is correct |
28 |
Correct |
165 ms |
22608 KB |
Output is correct |
29 |
Correct |
1 ms |
860 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
860 KB |
Output is correct |
32 |
Correct |
1 ms |
860 KB |
Output is correct |
33 |
Correct |
1 ms |
860 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
0 ms |
860 KB |
Output is correct |
36 |
Correct |
7 ms |
1784 KB |
Output is correct |
37 |
Correct |
168 ms |
22640 KB |
Output is correct |
38 |
Correct |
1 ms |
860 KB |
Output is correct |
39 |
Correct |
1 ms |
860 KB |
Output is correct |
40 |
Correct |
8 ms |
1628 KB |
Output is correct |
41 |
Correct |
165 ms |
22500 KB |
Output is correct |
42 |
Correct |
1 ms |
856 KB |
Output is correct |
43 |
Correct |
1 ms |
856 KB |
Output is correct |
44 |
Correct |
4 ms |
1372 KB |
Output is correct |
45 |
Correct |
80 ms |
12788 KB |
Output is correct |
46 |
Correct |
1 ms |
860 KB |
Output is correct |
47 |
Correct |
0 ms |
860 KB |
Output is correct |
48 |
Correct |
1 ms |
856 KB |
Output is correct |
49 |
Correct |
44 ms |
6328 KB |
Output is correct |
50 |
Correct |
170 ms |
22676 KB |
Output is correct |
51 |
Correct |
164 ms |
22612 KB |
Output is correct |
52 |
Correct |
178 ms |
22684 KB |
Output is correct |
53 |
Correct |
70 ms |
12628 KB |
Output is correct |
54 |
Correct |
72 ms |
12624 KB |
Output is correct |
55 |
Correct |
165 ms |
22516 KB |
Output is correct |
56 |
Correct |
173 ms |
22612 KB |
Output is correct |
57 |
Correct |
71 ms |
12532 KB |
Output is correct |
58 |
Correct |
1 ms |
860 KB |
Output is correct |
59 |
Correct |
0 ms |
860 KB |
Output is correct |
60 |
Correct |
4 ms |
1368 KB |
Output is correct |
61 |
Correct |
80 ms |
12628 KB |
Output is correct |
62 |
Correct |
1 ms |
856 KB |
Output is correct |
63 |
Correct |
1 ms |
856 KB |
Output is correct |
64 |
Correct |
1 ms |
1112 KB |
Output is correct |
65 |
Correct |
42 ms |
6228 KB |
Output is correct |
66 |
Correct |
72 ms |
12628 KB |
Output is correct |
67 |
Correct |
72 ms |
12628 KB |
Output is correct |
68 |
Correct |
71 ms |
12772 KB |
Output is correct |
69 |
Correct |
71 ms |
12628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
4 |
Correct |
0 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
860 KB |
Output is correct |
6 |
Correct |
9 ms |
1884 KB |
Output is correct |
7 |
Correct |
168 ms |
22444 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
1624 KB |
Output is correct |
13 |
Correct |
166 ms |
22448 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
0 ms |
860 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
82 ms |
12628 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
41 ms |
6288 KB |
Output is correct |
21 |
Correct |
164 ms |
22608 KB |
Output is correct |
22 |
Correct |
165 ms |
22608 KB |
Output is correct |
23 |
Correct |
209 ms |
22556 KB |
Output is correct |
24 |
Correct |
162 ms |
22612 KB |
Output is correct |
25 |
Correct |
71 ms |
12628 KB |
Output is correct |
26 |
Correct |
72 ms |
12624 KB |
Output is correct |
27 |
Correct |
172 ms |
22636 KB |
Output is correct |
28 |
Correct |
165 ms |
22608 KB |
Output is correct |
29 |
Correct |
1 ms |
860 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
860 KB |
Output is correct |
32 |
Correct |
1 ms |
860 KB |
Output is correct |
33 |
Correct |
1 ms |
860 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
0 ms |
860 KB |
Output is correct |
36 |
Correct |
7 ms |
1784 KB |
Output is correct |
37 |
Correct |
168 ms |
22640 KB |
Output is correct |
38 |
Correct |
1 ms |
860 KB |
Output is correct |
39 |
Correct |
1 ms |
860 KB |
Output is correct |
40 |
Correct |
8 ms |
1628 KB |
Output is correct |
41 |
Correct |
165 ms |
22500 KB |
Output is correct |
42 |
Correct |
1 ms |
856 KB |
Output is correct |
43 |
Correct |
1 ms |
856 KB |
Output is correct |
44 |
Correct |
4 ms |
1372 KB |
Output is correct |
45 |
Correct |
80 ms |
12788 KB |
Output is correct |
46 |
Correct |
1 ms |
860 KB |
Output is correct |
47 |
Correct |
0 ms |
860 KB |
Output is correct |
48 |
Correct |
1 ms |
856 KB |
Output is correct |
49 |
Correct |
44 ms |
6328 KB |
Output is correct |
50 |
Correct |
170 ms |
22676 KB |
Output is correct |
51 |
Correct |
164 ms |
22612 KB |
Output is correct |
52 |
Correct |
178 ms |
22684 KB |
Output is correct |
53 |
Correct |
70 ms |
12628 KB |
Output is correct |
54 |
Correct |
72 ms |
12624 KB |
Output is correct |
55 |
Correct |
165 ms |
22516 KB |
Output is correct |
56 |
Correct |
173 ms |
22612 KB |
Output is correct |
57 |
Correct |
71 ms |
12532 KB |
Output is correct |
58 |
Correct |
1 ms |
856 KB |
Output is correct |
59 |
Correct |
1 ms |
860 KB |
Output is correct |
60 |
Correct |
1 ms |
1116 KB |
Output is correct |
61 |
Correct |
41 ms |
6232 KB |
Output is correct |
62 |
Correct |
165 ms |
22512 KB |
Output is correct |
63 |
Correct |
168 ms |
22500 KB |
Output is correct |
64 |
Correct |
172 ms |
22612 KB |
Output is correct |
65 |
Correct |
1 ms |
856 KB |
Output is correct |
66 |
Correct |
41 ms |
6236 KB |
Output is correct |
67 |
Correct |
166 ms |
22552 KB |
Output is correct |
68 |
Correct |
186 ms |
22516 KB |
Output is correct |
69 |
Correct |
177 ms |
22528 KB |
Output is correct |
70 |
Correct |
1 ms |
860 KB |
Output is correct |
71 |
Correct |
1 ms |
860 KB |
Output is correct |
72 |
Correct |
1 ms |
860 KB |
Output is correct |
73 |
Correct |
41 ms |
6172 KB |
Output is correct |
74 |
Correct |
165 ms |
22500 KB |
Output is correct |
75 |
Correct |
178 ms |
22516 KB |
Output is correct |
76 |
Correct |
163 ms |
22612 KB |
Output is correct |
77 |
Correct |
163 ms |
22500 KB |
Output is correct |
78 |
Correct |
1 ms |
860 KB |
Output is correct |
79 |
Correct |
0 ms |
860 KB |
Output is correct |
80 |
Correct |
4 ms |
1368 KB |
Output is correct |
81 |
Correct |
80 ms |
12628 KB |
Output is correct |
82 |
Correct |
1 ms |
856 KB |
Output is correct |
83 |
Correct |
1 ms |
856 KB |
Output is correct |
84 |
Correct |
1 ms |
1112 KB |
Output is correct |
85 |
Correct |
42 ms |
6228 KB |
Output is correct |
86 |
Correct |
72 ms |
12628 KB |
Output is correct |
87 |
Correct |
72 ms |
12628 KB |
Output is correct |
88 |
Correct |
71 ms |
12772 KB |
Output is correct |
89 |
Correct |
71 ms |
12628 KB |
Output is correct |
90 |
Correct |
1 ms |
860 KB |
Output is correct |
91 |
Correct |
0 ms |
860 KB |
Output is correct |
92 |
Correct |
4 ms |
1372 KB |
Output is correct |
93 |
Correct |
80 ms |
12628 KB |
Output is correct |
94 |
Correct |
1 ms |
860 KB |
Output is correct |
95 |
Correct |
1 ms |
1064 KB |
Output is correct |
96 |
Correct |
1 ms |
856 KB |
Output is correct |
97 |
Correct |
19 ms |
4188 KB |
Output is correct |
98 |
Correct |
72 ms |
14676 KB |
Output is correct |
99 |
Correct |
72 ms |
14676 KB |
Output is correct |
100 |
Correct |
70 ms |
14672 KB |
Output is correct |
101 |
Correct |
73 ms |
14940 KB |
Output is correct |
102 |
Incorrect |
166 ms |
24516 KB |
Answer gives possible 1 while actual possible 0 |
103 |
Halted |
0 ms |
0 KB |
- |