#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
vector<ll> lnk1, lnk2;
ll find1(ll a) {
if (lnk1[a] != a) lnk1[a] = find1(lnk1[a]);
return lnk1[a];
}
ll find2(ll a) {
if (lnk2[a] != a) lnk2[a] = find2(lnk2[a]);
return lnk2[a];
}
void unite1(ll a, ll b) {
a = find1(a); b = find1(b);
lnk1[b] = a;
}
void unite2(ll a, ll b) {
a = find2(a); b = find2(b);
lnk2[b] = a;
}
int construct(vector<vector<int>> p) {
ll n = p.size();
lnk1 = vector<ll>(p.size());
lnk2 = vector<ll>(p.size());
for (int i = 0; i < n; i++) lnk1[i] = lnk2[i] = i;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (p[i][j] == 3) return 0;
if (p[i][j] == 2) unite2(i, j);
if (p[i][j] == 1) unite1(i, j);
}
}
vector<set<ll>> clubs1(n), clubs2(n);
for (int i = 0; i < n; i++) {
clubs1[find1(i)].insert(i);
clubs2[find2(i)].insert(find1(i));
}
vector<vector<int>> res(n, vector<int>(n));
for (int i = 0; i < n; i++) {
if (clubs2[i].size() > 1) {
if (clubs2.size() == 2) return 0;
ll prev = *--clubs2[i].end();
for (auto &e : clubs2[i]) {
if (res[prev][e]) return 0;
res[prev][e] = 1;
res[e][prev] = 1;
unite2(e, prev);
prev = e;
}
}
if (clubs1[i].size() > 1) {
ll prev = -1;
for (auto &e : clubs1[i]) {
if (prev != -1) {
if (res[prev][e]) return 0;
res[prev][e] = 1;
res[e][prev] = 1;
unite2(e, prev);
}
prev = e;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (p[i][j] == 0 && find2(i) == find2(j)) return 0;
if (p[i][j] == 2 && find1(i) == find1(j)) return 0;
}
}
build(res);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
115 ms |
22132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
115 ms |
22132 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1368 KB |
Output is correct |
13 |
Correct |
117 ms |
22292 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
58 ms |
12308 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
5832 KB |
Output is correct |
21 |
Correct |
115 ms |
22352 KB |
Output is correct |
22 |
Correct |
114 ms |
22356 KB |
Output is correct |
23 |
Correct |
125 ms |
22352 KB |
Output is correct |
24 |
Correct |
119 ms |
22352 KB |
Output is correct |
25 |
Correct |
51 ms |
12368 KB |
Output is correct |
26 |
Correct |
56 ms |
12308 KB |
Output is correct |
27 |
Correct |
124 ms |
22256 KB |
Output is correct |
28 |
Correct |
141 ms |
22356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
1300 KB |
Output is correct |
9 |
Correct |
120 ms |
22296 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1116 KB |
Output is correct |
13 |
Correct |
114 ms |
22336 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
12316 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
29 ms |
5840 KB |
Output is correct |
22 |
Correct |
115 ms |
22356 KB |
Output is correct |
23 |
Correct |
114 ms |
22356 KB |
Output is correct |
24 |
Correct |
126 ms |
22280 KB |
Output is correct |
25 |
Correct |
56 ms |
12372 KB |
Output is correct |
26 |
Correct |
50 ms |
14328 KB |
Output is correct |
27 |
Correct |
114 ms |
24148 KB |
Output is correct |
28 |
Correct |
121 ms |
24324 KB |
Output is correct |
29 |
Correct |
48 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
29 ms |
5968 KB |
Output is correct |
5 |
Correct |
119 ms |
22352 KB |
Output is correct |
6 |
Correct |
108 ms |
22352 KB |
Output is correct |
7 |
Correct |
108 ms |
22356 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
36 ms |
5972 KB |
Output is correct |
10 |
Correct |
142 ms |
22360 KB |
Output is correct |
11 |
Correct |
119 ms |
22280 KB |
Output is correct |
12 |
Correct |
127 ms |
22284 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
29 ms |
5912 KB |
Output is correct |
17 |
Correct |
117 ms |
22132 KB |
Output is correct |
18 |
Correct |
129 ms |
22292 KB |
Output is correct |
19 |
Correct |
125 ms |
22292 KB |
Output is correct |
20 |
Correct |
130 ms |
22284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
115 ms |
22132 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1368 KB |
Output is correct |
13 |
Correct |
117 ms |
22292 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
58 ms |
12308 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
5832 KB |
Output is correct |
21 |
Correct |
115 ms |
22352 KB |
Output is correct |
22 |
Correct |
114 ms |
22356 KB |
Output is correct |
23 |
Correct |
125 ms |
22352 KB |
Output is correct |
24 |
Correct |
119 ms |
22352 KB |
Output is correct |
25 |
Correct |
51 ms |
12368 KB |
Output is correct |
26 |
Correct |
56 ms |
12308 KB |
Output is correct |
27 |
Correct |
124 ms |
22256 KB |
Output is correct |
28 |
Correct |
141 ms |
22356 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1300 KB |
Output is correct |
37 |
Correct |
120 ms |
22296 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1116 KB |
Output is correct |
41 |
Correct |
114 ms |
22336 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
57 ms |
12316 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
29 ms |
5840 KB |
Output is correct |
50 |
Correct |
115 ms |
22356 KB |
Output is correct |
51 |
Correct |
114 ms |
22356 KB |
Output is correct |
52 |
Correct |
126 ms |
22280 KB |
Output is correct |
53 |
Correct |
56 ms |
12372 KB |
Output is correct |
54 |
Correct |
50 ms |
14328 KB |
Output is correct |
55 |
Correct |
114 ms |
24148 KB |
Output is correct |
56 |
Correct |
121 ms |
24324 KB |
Output is correct |
57 |
Correct |
48 ms |
14416 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
60 ms |
14208 KB |
Output is correct |
62 |
Correct |
1 ms |
356 KB |
Output is correct |
63 |
Correct |
0 ms |
432 KB |
Output is correct |
64 |
Correct |
1 ms |
352 KB |
Output is correct |
65 |
Correct |
32 ms |
6280 KB |
Output is correct |
66 |
Correct |
54 ms |
14204 KB |
Output is correct |
67 |
Correct |
54 ms |
14344 KB |
Output is correct |
68 |
Correct |
49 ms |
14216 KB |
Output is correct |
69 |
Correct |
52 ms |
14252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
115 ms |
22132 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1368 KB |
Output is correct |
13 |
Correct |
117 ms |
22292 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
58 ms |
12308 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
5832 KB |
Output is correct |
21 |
Correct |
115 ms |
22352 KB |
Output is correct |
22 |
Correct |
114 ms |
22356 KB |
Output is correct |
23 |
Correct |
125 ms |
22352 KB |
Output is correct |
24 |
Correct |
119 ms |
22352 KB |
Output is correct |
25 |
Correct |
51 ms |
12368 KB |
Output is correct |
26 |
Correct |
56 ms |
12308 KB |
Output is correct |
27 |
Correct |
124 ms |
22256 KB |
Output is correct |
28 |
Correct |
141 ms |
22356 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1300 KB |
Output is correct |
37 |
Correct |
120 ms |
22296 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1116 KB |
Output is correct |
41 |
Correct |
114 ms |
22336 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
57 ms |
12316 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
29 ms |
5840 KB |
Output is correct |
50 |
Correct |
115 ms |
22356 KB |
Output is correct |
51 |
Correct |
114 ms |
22356 KB |
Output is correct |
52 |
Correct |
126 ms |
22280 KB |
Output is correct |
53 |
Correct |
56 ms |
12372 KB |
Output is correct |
54 |
Correct |
50 ms |
14328 KB |
Output is correct |
55 |
Correct |
114 ms |
24148 KB |
Output is correct |
56 |
Correct |
121 ms |
24324 KB |
Output is correct |
57 |
Correct |
48 ms |
14416 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
29 ms |
5968 KB |
Output is correct |
62 |
Correct |
119 ms |
22352 KB |
Output is correct |
63 |
Correct |
108 ms |
22352 KB |
Output is correct |
64 |
Correct |
108 ms |
22356 KB |
Output is correct |
65 |
Correct |
0 ms |
600 KB |
Output is correct |
66 |
Correct |
36 ms |
5972 KB |
Output is correct |
67 |
Correct |
142 ms |
22360 KB |
Output is correct |
68 |
Correct |
119 ms |
22280 KB |
Output is correct |
69 |
Correct |
127 ms |
22284 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
29 ms |
5912 KB |
Output is correct |
74 |
Correct |
117 ms |
22132 KB |
Output is correct |
75 |
Correct |
129 ms |
22292 KB |
Output is correct |
76 |
Correct |
125 ms |
22292 KB |
Output is correct |
77 |
Correct |
130 ms |
22284 KB |
Output is correct |
78 |
Correct |
1 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
860 KB |
Output is correct |
81 |
Correct |
60 ms |
14208 KB |
Output is correct |
82 |
Correct |
1 ms |
356 KB |
Output is correct |
83 |
Correct |
0 ms |
432 KB |
Output is correct |
84 |
Correct |
1 ms |
352 KB |
Output is correct |
85 |
Correct |
32 ms |
6280 KB |
Output is correct |
86 |
Correct |
54 ms |
14204 KB |
Output is correct |
87 |
Correct |
54 ms |
14344 KB |
Output is correct |
88 |
Correct |
49 ms |
14216 KB |
Output is correct |
89 |
Correct |
52 ms |
14252 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
2 ms |
684 KB |
Output is correct |
93 |
Correct |
57 ms |
10244 KB |
Output is correct |
94 |
Correct |
0 ms |
348 KB |
Output is correct |
95 |
Correct |
1 ms |
436 KB |
Output is correct |
96 |
Correct |
0 ms |
604 KB |
Output is correct |
97 |
Correct |
10 ms |
2824 KB |
Output is correct |
98 |
Correct |
47 ms |
10236 KB |
Output is correct |
99 |
Correct |
50 ms |
10244 KB |
Output is correct |
100 |
Correct |
52 ms |
10120 KB |
Output is correct |
101 |
Correct |
52 ms |
10260 KB |
Output is correct |
102 |
Correct |
61 ms |
10248 KB |
Output is correct |
103 |
Correct |
50 ms |
10120 KB |
Output is correct |
104 |
Correct |
50 ms |
10116 KB |
Output is correct |
105 |
Correct |
54 ms |
10108 KB |
Output is correct |