#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e3 + 1;
int N;
int P[NMAX][NMAX];
int head[NMAX];
bool Edge[NMAX][NMAX];
vector < int > roots;
vector < int > List[NMAX];
bool OK = 1;
class DisjointSets
{
int T[NMAX], Size[NMAX];
private:
inline int Find (int X)
{
if(X == T[X])
return X;
return (T[X] = Find(T[X]));
}
inline void my_swap (int &x, int &y)
{
x = (x ^ y), y = (x ^ y), x = (x ^ y);
return;
}
public:
inline void Initialize (int N)
{
for(int i = 1; i <= N; ++i)
T[i] = i, Size[i] = 1;
return;
}
inline bool Unify (int X, int Y)
{
X = Find(X), Y = Find(Y);
if(X == Y)
return 0;
if(Size[X] < Size[Y])
my_swap(X, Y);
Size[X] += Size[Y], Size[Y] = 0;
T[Y] = X;
return 1;
}
inline int Who_is_the_boss (int Node)
{
return Find(Node);
}
} DSU, cycles;
void Build_type_1 ()
{
DSU.Initialize(N);
for(int i = 1; i <= N; ++i)
for(int j = 1; j <= N; ++j)
if(P[i][j] == 1)
DSU.Unify(i, j);
for(int i = 1; i <= N; ++i)
{
head[i] = DSU.Who_is_the_boss(i);
if(i == head[i])
roots.push_back(i);
else
Edge[i][head[i]] = Edge[head[i]][i] = 1;
}
return;
}
void Build_type_2 ()
{
cycles.Initialize(N);
for(int i = 0; i < (int)roots.size() - 1; ++i)
for(int j = i + 1; j < (int)roots.size(); ++j)
if(P[roots[i]][roots[j]] == 2)
cycles.Unify(roots[i], roots[j]);
for(auto it : roots)
{
int rep = cycles.Who_is_the_boss(it);
List[rep].push_back(it);
}
for(int i = 1; i <= N; ++i)
if((int)List[i].size() > 2)
{
for(int j = 0; j < (int)List[i].size() - 1; ++j)
Edge[List[i][j]][List[i][j + 1]] = Edge[List[i][j + 1]][List[i][j]] = 1;
for(int j = 0; j < (int)List[i].size() - 1; ++j)
for(int k = j + 1; k < (int)List[i].size(); ++k)
if(P[List[i][j]][List[i][k]] != 2)
OK = 0;
int First = List[i][0];
int Last = List[i][(int)List[i].size() - 1];
Edge[First][Last] = Edge[Last][First] = 1;
}
else if((int)List[i].size() == 2)
OK = 0;
return;
}
int construct (vector < vector < int > > p)
{
N = (int)p.size();
for(int i = 0; i < N; ++i)
for(int j = 0; j < N; ++j)
{
P[i + 1][j + 1] = p[i][j];
if(p[i][j] == 3)
return 0;
}
Build_type_1();
for(int i = 1; i <= N; ++i)
for(int j = 1; j <= N; ++j)
if(P[i][j] == 0)
if(head[i] == head[j])
return 0;
Build_type_2();
if(!OK)
return 0;
///
vector < vector < int > > ans;
for(int i = 0; i < N; ++i)
{
vector < int > _temp;
for(int j = 0; j < N; ++j)
if(Edge[i + 1][j + 1])
_temp.push_back(1);
else
_temp.push_back(0);
ans.push_back(_temp);
}
build(ans);
///
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
8 ms |
2152 KB |
Output is correct |
7 |
Correct |
172 ms |
27040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
8 ms |
2152 KB |
Output is correct |
7 |
Correct |
172 ms |
27040 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
1996 KB |
Output is correct |
13 |
Correct |
176 ms |
26008 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
1612 KB |
Output is correct |
17 |
Correct |
82 ms |
13096 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
44 ms |
8260 KB |
Output is correct |
21 |
Correct |
190 ms |
26908 KB |
Output is correct |
22 |
Correct |
168 ms |
26908 KB |
Output is correct |
23 |
Correct |
194 ms |
26948 KB |
Output is correct |
24 |
Correct |
176 ms |
26180 KB |
Output is correct |
25 |
Correct |
69 ms |
13084 KB |
Output is correct |
26 |
Correct |
69 ms |
13092 KB |
Output is correct |
27 |
Correct |
180 ms |
26948 KB |
Output is correct |
28 |
Correct |
172 ms |
26180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
8 ms |
1996 KB |
Output is correct |
9 |
Correct |
169 ms |
26020 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
8 ms |
2124 KB |
Output is correct |
13 |
Correct |
203 ms |
26888 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
5 ms |
1620 KB |
Output is correct |
17 |
Correct |
93 ms |
15120 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 |
328 KB |
Output is correct |
21 |
Correct |
47 ms |
8744 KB |
Output is correct |
22 |
Correct |
172 ms |
28948 KB |
Output is correct |
23 |
Correct |
179 ms |
28956 KB |
Output is correct |
24 |
Correct |
184 ms |
28964 KB |
Output is correct |
25 |
Correct |
69 ms |
14236 KB |
Output is correct |
26 |
Correct |
74 ms |
14988 KB |
Output is correct |
27 |
Correct |
174 ms |
29008 KB |
Output is correct |
28 |
Correct |
203 ms |
28956 KB |
Output is correct |
29 |
Correct |
70 ms |
14276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
45 ms |
8228 KB |
Output is correct |
5 |
Correct |
173 ms |
26948 KB |
Output is correct |
6 |
Correct |
179 ms |
26908 KB |
Output is correct |
7 |
Correct |
188 ms |
26912 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
46 ms |
8168 KB |
Output is correct |
10 |
Correct |
173 ms |
26908 KB |
Output is correct |
11 |
Correct |
167 ms |
26928 KB |
Output is correct |
12 |
Correct |
181 ms |
26924 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
44 ms |
8224 KB |
Output is correct |
17 |
Correct |
171 ms |
26904 KB |
Output is correct |
18 |
Correct |
190 ms |
26908 KB |
Output is correct |
19 |
Correct |
169 ms |
26924 KB |
Output is correct |
20 |
Correct |
177 ms |
26228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
8 ms |
2152 KB |
Output is correct |
7 |
Correct |
172 ms |
27040 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
1996 KB |
Output is correct |
13 |
Correct |
176 ms |
26008 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
1612 KB |
Output is correct |
17 |
Correct |
82 ms |
13096 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
44 ms |
8260 KB |
Output is correct |
21 |
Correct |
190 ms |
26908 KB |
Output is correct |
22 |
Correct |
168 ms |
26908 KB |
Output is correct |
23 |
Correct |
194 ms |
26948 KB |
Output is correct |
24 |
Correct |
176 ms |
26180 KB |
Output is correct |
25 |
Correct |
69 ms |
13084 KB |
Output is correct |
26 |
Correct |
69 ms |
13092 KB |
Output is correct |
27 |
Correct |
180 ms |
26948 KB |
Output is correct |
28 |
Correct |
172 ms |
26180 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
8 ms |
1996 KB |
Output is correct |
37 |
Correct |
169 ms |
26020 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
8 ms |
2124 KB |
Output is correct |
41 |
Correct |
203 ms |
26888 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
324 KB |
Output is correct |
44 |
Correct |
5 ms |
1620 KB |
Output is correct |
45 |
Correct |
93 ms |
15120 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 |
328 KB |
Output is correct |
49 |
Correct |
47 ms |
8744 KB |
Output is correct |
50 |
Correct |
172 ms |
28948 KB |
Output is correct |
51 |
Correct |
179 ms |
28956 KB |
Output is correct |
52 |
Correct |
184 ms |
28964 KB |
Output is correct |
53 |
Correct |
69 ms |
14236 KB |
Output is correct |
54 |
Correct |
74 ms |
14988 KB |
Output is correct |
55 |
Correct |
174 ms |
29008 KB |
Output is correct |
56 |
Correct |
203 ms |
28956 KB |
Output is correct |
57 |
Correct |
70 ms |
14276 KB |
Output is correct |
58 |
Correct |
0 ms |
316 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
4 ms |
1620 KB |
Output is correct |
61 |
Correct |
78 ms |
14988 KB |
Output is correct |
62 |
Correct |
0 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 |
51 ms |
8720 KB |
Output is correct |
66 |
Correct |
80 ms |
15044 KB |
Output is correct |
67 |
Correct |
68 ms |
14992 KB |
Output is correct |
68 |
Correct |
70 ms |
14992 KB |
Output is correct |
69 |
Correct |
71 ms |
14224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
8 ms |
2152 KB |
Output is correct |
7 |
Correct |
172 ms |
27040 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
1996 KB |
Output is correct |
13 |
Correct |
176 ms |
26008 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
1612 KB |
Output is correct |
17 |
Correct |
82 ms |
13096 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
44 ms |
8260 KB |
Output is correct |
21 |
Correct |
190 ms |
26908 KB |
Output is correct |
22 |
Correct |
168 ms |
26908 KB |
Output is correct |
23 |
Correct |
194 ms |
26948 KB |
Output is correct |
24 |
Correct |
176 ms |
26180 KB |
Output is correct |
25 |
Correct |
69 ms |
13084 KB |
Output is correct |
26 |
Correct |
69 ms |
13092 KB |
Output is correct |
27 |
Correct |
180 ms |
26948 KB |
Output is correct |
28 |
Correct |
172 ms |
26180 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
8 ms |
1996 KB |
Output is correct |
37 |
Correct |
169 ms |
26020 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
8 ms |
2124 KB |
Output is correct |
41 |
Correct |
203 ms |
26888 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
324 KB |
Output is correct |
44 |
Correct |
5 ms |
1620 KB |
Output is correct |
45 |
Correct |
93 ms |
15120 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 |
328 KB |
Output is correct |
49 |
Correct |
47 ms |
8744 KB |
Output is correct |
50 |
Correct |
172 ms |
28948 KB |
Output is correct |
51 |
Correct |
179 ms |
28956 KB |
Output is correct |
52 |
Correct |
184 ms |
28964 KB |
Output is correct |
53 |
Correct |
69 ms |
14236 KB |
Output is correct |
54 |
Correct |
74 ms |
14988 KB |
Output is correct |
55 |
Correct |
174 ms |
29008 KB |
Output is correct |
56 |
Correct |
203 ms |
28956 KB |
Output is correct |
57 |
Correct |
70 ms |
14276 KB |
Output is correct |
58 |
Correct |
0 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
45 ms |
8228 KB |
Output is correct |
62 |
Correct |
173 ms |
26948 KB |
Output is correct |
63 |
Correct |
179 ms |
26908 KB |
Output is correct |
64 |
Correct |
188 ms |
26912 KB |
Output is correct |
65 |
Correct |
0 ms |
332 KB |
Output is correct |
66 |
Correct |
46 ms |
8168 KB |
Output is correct |
67 |
Correct |
173 ms |
26908 KB |
Output is correct |
68 |
Correct |
167 ms |
26928 KB |
Output is correct |
69 |
Correct |
181 ms |
26924 KB |
Output is correct |
70 |
Correct |
0 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
0 ms |
332 KB |
Output is correct |
73 |
Correct |
44 ms |
8224 KB |
Output is correct |
74 |
Correct |
171 ms |
26904 KB |
Output is correct |
75 |
Correct |
190 ms |
26908 KB |
Output is correct |
76 |
Correct |
169 ms |
26924 KB |
Output is correct |
77 |
Correct |
177 ms |
26228 KB |
Output is correct |
78 |
Correct |
0 ms |
316 KB |
Output is correct |
79 |
Correct |
0 ms |
332 KB |
Output is correct |
80 |
Correct |
4 ms |
1620 KB |
Output is correct |
81 |
Correct |
78 ms |
14988 KB |
Output is correct |
82 |
Correct |
0 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 |
51 ms |
8720 KB |
Output is correct |
86 |
Correct |
80 ms |
15044 KB |
Output is correct |
87 |
Correct |
68 ms |
14992 KB |
Output is correct |
88 |
Correct |
70 ms |
14992 KB |
Output is correct |
89 |
Correct |
71 ms |
14224 KB |
Output is correct |
90 |
Correct |
1 ms |
332 KB |
Output is correct |
91 |
Correct |
0 ms |
332 KB |
Output is correct |
92 |
Correct |
3 ms |
724 KB |
Output is correct |
93 |
Correct |
72 ms |
10136 KB |
Output is correct |
94 |
Correct |
0 ms |
332 KB |
Output is correct |
95 |
Correct |
1 ms |
384 KB |
Output is correct |
96 |
Correct |
1 ms |
328 KB |
Output is correct |
97 |
Correct |
16 ms |
2840 KB |
Output is correct |
98 |
Correct |
65 ms |
10264 KB |
Output is correct |
99 |
Correct |
68 ms |
10692 KB |
Output is correct |
100 |
Correct |
68 ms |
10384 KB |
Output is correct |
101 |
Correct |
88 ms |
11408 KB |
Output is correct |
102 |
Correct |
66 ms |
10128 KB |
Output is correct |
103 |
Correct |
64 ms |
10128 KB |
Output is correct |
104 |
Correct |
71 ms |
10056 KB |
Output is correct |
105 |
Correct |
79 ms |
10140 KB |
Output is correct |