#include<supertrees.h>
#include<bits/stdc++.h>
using namespace std;
int cpar[1005], spar[1005];
set<int>st[1005];
int sfind(int u)
{
if (spar[u] == u)
return u;
return spar[u] = sfind(spar[u]);
}
void sunion(int x, int y)
{
x = sfind(x);
y = sfind(y);
spar[x] = y;
}
int cfind(int u)
{
if (cpar[u] == u)
return u;
return cpar[u] = cfind(cpar[u]);
}
void cunion(int x, int y)
{
x = cfind(x);
y = cfind(y);
cpar[x] = y;
}
int construct(vector<vector<int>>p)
{
int n = p.size();
vector<vector<int>>answer(n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
cpar[i] = spar[i] = i;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (p[i][j] == 0)
continue;
if (p[i][j] == 1)
{
if (sfind(i) == sfind(j))
continue;
sunion(i, j);
answer[i][j] = answer[j][i] = 1;
}
if (p[i][j] >= 2)
cunion(i, j);
}
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (p[i][j] == 0)
{
if (sfind(i) == sfind(j) or cfind(i) == cfind(j))
return 0;
}
if (p[i][j] == 1)
{
if (sfind(i) != sfind(j))
return 0;
}
if (p[i][j] >= 2)
{
if (sfind(i) == sfind(j) or cfind(i) != cfind(j))
return 0;
st[cfind(i)].insert(p[i][j]);
}
}
}
for (int i = 0; i < n; i++)
{
if (cfind(i) != i)
continue;
set<int>rem;
for (int j = 0; j < n; j++)
{
if (cfind(j) != i)
continue;
rem.insert(sfind(j));
}
vector<int>v;
for (auto it : rem)
v.push_back(it);
int k = v.size();
if (k <= 1)
continue;
if (st[i].size() >= 2 or * st[i].begin() == 3)
return 0;
if (k <= 2)
return 0;
for (int j = 0; j < k; j++)
{
int nj = (j + 1) % k;
answer[v[j]][v[nj]] = answer[v[nj]][v[j]] = 1;
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
255 ms |
24004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
255 ms |
24004 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
11 ms |
1228 KB |
Output is correct |
13 |
Correct |
254 ms |
23988 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
844 KB |
Output is correct |
17 |
Correct |
121 ms |
14116 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
66 ms |
6212 KB |
Output is correct |
21 |
Correct |
253 ms |
23988 KB |
Output is correct |
22 |
Correct |
255 ms |
24004 KB |
Output is correct |
23 |
Correct |
267 ms |
24128 KB |
Output is correct |
24 |
Correct |
252 ms |
24004 KB |
Output is correct |
25 |
Correct |
118 ms |
14128 KB |
Output is correct |
26 |
Correct |
111 ms |
14128 KB |
Output is correct |
27 |
Correct |
261 ms |
23980 KB |
Output is correct |
28 |
Correct |
252 ms |
24132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
416 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
13 ms |
1280 KB |
Output is correct |
9 |
Correct |
255 ms |
24004 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
12 ms |
1268 KB |
Output is correct |
13 |
Correct |
258 ms |
24184 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
6 ms |
868 KB |
Output is correct |
17 |
Correct |
123 ms |
14116 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
63 ms |
6260 KB |
Output is correct |
22 |
Correct |
255 ms |
24108 KB |
Output is correct |
23 |
Correct |
272 ms |
24000 KB |
Output is correct |
24 |
Correct |
267 ms |
24036 KB |
Output is correct |
25 |
Correct |
115 ms |
14116 KB |
Output is correct |
26 |
Correct |
114 ms |
14132 KB |
Output is correct |
27 |
Correct |
252 ms |
23984 KB |
Output is correct |
28 |
Correct |
267 ms |
23972 KB |
Output is correct |
29 |
Correct |
119 ms |
14252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
64 ms |
6256 KB |
Output is correct |
5 |
Correct |
261 ms |
24056 KB |
Output is correct |
6 |
Correct |
254 ms |
24004 KB |
Output is correct |
7 |
Correct |
282 ms |
24004 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
63 ms |
6304 KB |
Output is correct |
10 |
Correct |
257 ms |
24040 KB |
Output is correct |
11 |
Correct |
260 ms |
24176 KB |
Output is correct |
12 |
Correct |
263 ms |
24016 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
66 ms |
6308 KB |
Output is correct |
17 |
Correct |
252 ms |
23968 KB |
Output is correct |
18 |
Correct |
259 ms |
24004 KB |
Output is correct |
19 |
Correct |
255 ms |
24012 KB |
Output is correct |
20 |
Correct |
252 ms |
24004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
255 ms |
24004 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
11 ms |
1228 KB |
Output is correct |
13 |
Correct |
254 ms |
23988 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
844 KB |
Output is correct |
17 |
Correct |
121 ms |
14116 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
66 ms |
6212 KB |
Output is correct |
21 |
Correct |
253 ms |
23988 KB |
Output is correct |
22 |
Correct |
255 ms |
24004 KB |
Output is correct |
23 |
Correct |
267 ms |
24128 KB |
Output is correct |
24 |
Correct |
252 ms |
24004 KB |
Output is correct |
25 |
Correct |
118 ms |
14128 KB |
Output is correct |
26 |
Correct |
111 ms |
14128 KB |
Output is correct |
27 |
Correct |
261 ms |
23980 KB |
Output is correct |
28 |
Correct |
252 ms |
24132 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
416 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
13 ms |
1280 KB |
Output is correct |
37 |
Correct |
255 ms |
24004 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
12 ms |
1268 KB |
Output is correct |
41 |
Correct |
258 ms |
24184 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
352 KB |
Output is correct |
44 |
Correct |
6 ms |
868 KB |
Output is correct |
45 |
Correct |
123 ms |
14116 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
63 ms |
6260 KB |
Output is correct |
50 |
Correct |
255 ms |
24108 KB |
Output is correct |
51 |
Correct |
272 ms |
24000 KB |
Output is correct |
52 |
Correct |
267 ms |
24036 KB |
Output is correct |
53 |
Correct |
115 ms |
14116 KB |
Output is correct |
54 |
Correct |
114 ms |
14132 KB |
Output is correct |
55 |
Correct |
252 ms |
23984 KB |
Output is correct |
56 |
Correct |
267 ms |
23972 KB |
Output is correct |
57 |
Correct |
119 ms |
14252 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
5 ms |
844 KB |
Output is correct |
61 |
Correct |
123 ms |
14148 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
64 ms |
6308 KB |
Output is correct |
66 |
Correct |
115 ms |
14128 KB |
Output is correct |
67 |
Correct |
114 ms |
14120 KB |
Output is correct |
68 |
Correct |
111 ms |
14128 KB |
Output is correct |
69 |
Correct |
113 ms |
14120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
255 ms |
24004 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
11 ms |
1228 KB |
Output is correct |
13 |
Correct |
254 ms |
23988 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
844 KB |
Output is correct |
17 |
Correct |
121 ms |
14116 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
66 ms |
6212 KB |
Output is correct |
21 |
Correct |
253 ms |
23988 KB |
Output is correct |
22 |
Correct |
255 ms |
24004 KB |
Output is correct |
23 |
Correct |
267 ms |
24128 KB |
Output is correct |
24 |
Correct |
252 ms |
24004 KB |
Output is correct |
25 |
Correct |
118 ms |
14128 KB |
Output is correct |
26 |
Correct |
111 ms |
14128 KB |
Output is correct |
27 |
Correct |
261 ms |
23980 KB |
Output is correct |
28 |
Correct |
252 ms |
24132 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
416 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
13 ms |
1280 KB |
Output is correct |
37 |
Correct |
255 ms |
24004 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
12 ms |
1268 KB |
Output is correct |
41 |
Correct |
258 ms |
24184 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
352 KB |
Output is correct |
44 |
Correct |
6 ms |
868 KB |
Output is correct |
45 |
Correct |
123 ms |
14116 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
63 ms |
6260 KB |
Output is correct |
50 |
Correct |
255 ms |
24108 KB |
Output is correct |
51 |
Correct |
272 ms |
24000 KB |
Output is correct |
52 |
Correct |
267 ms |
24036 KB |
Output is correct |
53 |
Correct |
115 ms |
14116 KB |
Output is correct |
54 |
Correct |
114 ms |
14132 KB |
Output is correct |
55 |
Correct |
252 ms |
23984 KB |
Output is correct |
56 |
Correct |
267 ms |
23972 KB |
Output is correct |
57 |
Correct |
119 ms |
14252 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
64 ms |
6256 KB |
Output is correct |
62 |
Correct |
261 ms |
24056 KB |
Output is correct |
63 |
Correct |
254 ms |
24004 KB |
Output is correct |
64 |
Correct |
282 ms |
24004 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
63 ms |
6304 KB |
Output is correct |
67 |
Correct |
257 ms |
24040 KB |
Output is correct |
68 |
Correct |
260 ms |
24176 KB |
Output is correct |
69 |
Correct |
263 ms |
24016 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
66 ms |
6308 KB |
Output is correct |
74 |
Correct |
252 ms |
23968 KB |
Output is correct |
75 |
Correct |
259 ms |
24004 KB |
Output is correct |
76 |
Correct |
255 ms |
24012 KB |
Output is correct |
77 |
Correct |
252 ms |
24004 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
336 KB |
Output is correct |
80 |
Correct |
5 ms |
844 KB |
Output is correct |
81 |
Correct |
123 ms |
14148 KB |
Output is correct |
82 |
Correct |
1 ms |
332 KB |
Output is correct |
83 |
Correct |
1 ms |
332 KB |
Output is correct |
84 |
Correct |
1 ms |
332 KB |
Output is correct |
85 |
Correct |
64 ms |
6308 KB |
Output is correct |
86 |
Correct |
115 ms |
14128 KB |
Output is correct |
87 |
Correct |
114 ms |
14120 KB |
Output is correct |
88 |
Correct |
111 ms |
14128 KB |
Output is correct |
89 |
Correct |
113 ms |
14120 KB |
Output is correct |
90 |
Correct |
1 ms |
332 KB |
Output is correct |
91 |
Correct |
1 ms |
348 KB |
Output is correct |
92 |
Correct |
6 ms |
848 KB |
Output is correct |
93 |
Correct |
118 ms |
14124 KB |
Output is correct |
94 |
Correct |
1 ms |
332 KB |
Output is correct |
95 |
Correct |
1 ms |
348 KB |
Output is correct |
96 |
Correct |
1 ms |
332 KB |
Output is correct |
97 |
Correct |
29 ms |
3732 KB |
Output is correct |
98 |
Correct |
117 ms |
14036 KB |
Output is correct |
99 |
Correct |
112 ms |
14132 KB |
Output is correct |
100 |
Correct |
126 ms |
14116 KB |
Output is correct |
101 |
Correct |
116 ms |
14116 KB |
Output is correct |
102 |
Correct |
118 ms |
14128 KB |
Output is correct |
103 |
Correct |
126 ms |
14148 KB |
Output is correct |
104 |
Correct |
118 ms |
14116 KB |
Output is correct |
105 |
Correct |
119 ms |
14176 KB |
Output is correct |