#include <bits/stdc++.h>
#include "supertrees.h"
#define fi first
#define se second
#define pii pair <int, int>
#define pll pair <ll, ll>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define p_b push_back
using namespace std;
typedef long long ll;
const ll N = 2e3;
int p1[N], p2[N];
int get(int x){
if(p1[x] != x)p1[x] = get(p1[x]);
return p1[x];
}
int get1(int x){
if(p2[x] != x)p2[x] = get1(p2[x]);
return p2[x];
}
int construct(vector <vector <int> > p){
int n = sz(p);
vector <vector <int> > answer(n, vector <int> (n, 0));
vector <vector <int> > mb(n, vector <int> (n, 0));
iota(p1, p1 + n, 0);
iota(p2, p2 + n, 0);
int msk = 1;
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++){
if(p[i][j] == 1 && get(i) != get(j))p1[get(i)] = get(j);
msk |= 1 << p[i][j];
}
for(int i = 0; i < n; i++)if(get(i) == i){
vector <int> vc;
for(int j = 0; j < n; j++){
if(get(j) == i){
vc.p_b(j);
for(int i1 = 0; i1 < n; i1++)if(p[j][i1] == 2){
if(get(i1) == get(j))return 0;
mb[i][i1] = 1;
}
}
}
for(int j = 1; j < sz(vc); j++){
answer[vc[j - 1]][vc[j]] = answer[vc[j]][vc[j - 1]] = 1;
}
for(int j = 0; j < n; j++)if(mb[i][j]){
if(get1(get(j)) != get1(i)){
p2[get1(get(j))] = get1(i);
}
}
}
for(int i = 0; i < n; i++)if(get1(i) == i){
vector <int> vc;
for(int j = 0; j < n; j++)if(get(j) == j){
if(get1(j) == i)vc.p_b(j);
}
if(!sz(vc))continue;
if(sz(vc) == 2)return 0;
for(int j = 1; j < sz(vc); j++){
answer[vc[j - 1]][vc[j]] = answer[vc[j]][vc[j - 1]] = 1;
}
if(sz(vc) != 1){
answer[vc[0]][vc.back()] = answer[vc.back()][vc[0]] = 1;
}
}
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
int m = 0;
if(get(i) == get(j))m = 1;
if(get1(i) == get1(j))m = 2;
if(m != p[i][j] && msk != 7)return 0;
}
}
iota(p1, p1 + n, 0);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(answer[i][j] && get(i) != get(j)){
p1[get(i)] = get(j);
}
}
}
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++){
if(p[i][j] && get(i) != get(j))return 0;
if(!p[i][j] && get(i) == get(j))return 0;
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
274 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
274 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
276 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
129 ms |
16088 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
67 ms |
6808 KB |
Output is correct |
21 |
Correct |
257 ms |
26104 KB |
Output is correct |
22 |
Correct |
269 ms |
26104 KB |
Output is correct |
23 |
Correct |
276 ms |
26076 KB |
Output is correct |
24 |
Correct |
270 ms |
26176 KB |
Output is correct |
25 |
Correct |
115 ms |
16120 KB |
Output is correct |
26 |
Correct |
120 ms |
16120 KB |
Output is correct |
27 |
Correct |
311 ms |
26108 KB |
Output is correct |
28 |
Correct |
271 ms |
26124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
16 ms |
1408 KB |
Output is correct |
9 |
Correct |
282 ms |
26104 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
270 ms |
26108 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
139 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
77 ms |
6860 KB |
Output is correct |
22 |
Correct |
284 ms |
26104 KB |
Output is correct |
23 |
Correct |
280 ms |
26104 KB |
Output is correct |
24 |
Correct |
280 ms |
26104 KB |
Output is correct |
25 |
Correct |
116 ms |
16120 KB |
Output is correct |
26 |
Correct |
124 ms |
16120 KB |
Output is correct |
27 |
Correct |
281 ms |
26104 KB |
Output is correct |
28 |
Correct |
307 ms |
26104 KB |
Output is correct |
29 |
Correct |
117 ms |
16092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
66 ms |
6776 KB |
Output is correct |
5 |
Correct |
281 ms |
26076 KB |
Output is correct |
6 |
Correct |
262 ms |
26072 KB |
Output is correct |
7 |
Correct |
292 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
65 ms |
6776 KB |
Output is correct |
10 |
Correct |
271 ms |
26104 KB |
Output is correct |
11 |
Correct |
278 ms |
26104 KB |
Output is correct |
12 |
Correct |
294 ms |
26040 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
66 ms |
6776 KB |
Output is correct |
17 |
Correct |
263 ms |
26104 KB |
Output is correct |
18 |
Correct |
270 ms |
26104 KB |
Output is correct |
19 |
Correct |
265 ms |
26108 KB |
Output is correct |
20 |
Correct |
261 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
274 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
276 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
129 ms |
16088 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
67 ms |
6808 KB |
Output is correct |
21 |
Correct |
257 ms |
26104 KB |
Output is correct |
22 |
Correct |
269 ms |
26104 KB |
Output is correct |
23 |
Correct |
276 ms |
26076 KB |
Output is correct |
24 |
Correct |
270 ms |
26176 KB |
Output is correct |
25 |
Correct |
115 ms |
16120 KB |
Output is correct |
26 |
Correct |
120 ms |
16120 KB |
Output is correct |
27 |
Correct |
311 ms |
26108 KB |
Output is correct |
28 |
Correct |
271 ms |
26124 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
0 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
16 ms |
1408 KB |
Output is correct |
37 |
Correct |
282 ms |
26104 KB |
Output is correct |
38 |
Correct |
0 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
13 ms |
1408 KB |
Output is correct |
41 |
Correct |
270 ms |
26108 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
139 ms |
16120 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
77 ms |
6860 KB |
Output is correct |
50 |
Correct |
284 ms |
26104 KB |
Output is correct |
51 |
Correct |
280 ms |
26104 KB |
Output is correct |
52 |
Correct |
280 ms |
26104 KB |
Output is correct |
53 |
Correct |
116 ms |
16120 KB |
Output is correct |
54 |
Correct |
124 ms |
16120 KB |
Output is correct |
55 |
Correct |
281 ms |
26104 KB |
Output is correct |
56 |
Correct |
307 ms |
26104 KB |
Output is correct |
57 |
Correct |
117 ms |
16092 KB |
Output is correct |
58 |
Correct |
0 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
5 ms |
1024 KB |
Output is correct |
61 |
Correct |
120 ms |
16092 KB |
Output is correct |
62 |
Correct |
0 ms |
256 KB |
Output is correct |
63 |
Correct |
0 ms |
256 KB |
Output is correct |
64 |
Correct |
0 ms |
256 KB |
Output is correct |
65 |
Correct |
68 ms |
6836 KB |
Output is correct |
66 |
Correct |
127 ms |
16124 KB |
Output is correct |
67 |
Correct |
126 ms |
16088 KB |
Output is correct |
68 |
Correct |
123 ms |
16124 KB |
Output is correct |
69 |
Correct |
118 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
274 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
276 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
129 ms |
16088 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
67 ms |
6808 KB |
Output is correct |
21 |
Correct |
257 ms |
26104 KB |
Output is correct |
22 |
Correct |
269 ms |
26104 KB |
Output is correct |
23 |
Correct |
276 ms |
26076 KB |
Output is correct |
24 |
Correct |
270 ms |
26176 KB |
Output is correct |
25 |
Correct |
115 ms |
16120 KB |
Output is correct |
26 |
Correct |
120 ms |
16120 KB |
Output is correct |
27 |
Correct |
311 ms |
26108 KB |
Output is correct |
28 |
Correct |
271 ms |
26124 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
0 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
16 ms |
1408 KB |
Output is correct |
37 |
Correct |
282 ms |
26104 KB |
Output is correct |
38 |
Correct |
0 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
13 ms |
1408 KB |
Output is correct |
41 |
Correct |
270 ms |
26108 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
139 ms |
16120 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
77 ms |
6860 KB |
Output is correct |
50 |
Correct |
284 ms |
26104 KB |
Output is correct |
51 |
Correct |
280 ms |
26104 KB |
Output is correct |
52 |
Correct |
280 ms |
26104 KB |
Output is correct |
53 |
Correct |
116 ms |
16120 KB |
Output is correct |
54 |
Correct |
124 ms |
16120 KB |
Output is correct |
55 |
Correct |
281 ms |
26104 KB |
Output is correct |
56 |
Correct |
307 ms |
26104 KB |
Output is correct |
57 |
Correct |
117 ms |
16092 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
0 ms |
384 KB |
Output is correct |
61 |
Correct |
66 ms |
6776 KB |
Output is correct |
62 |
Correct |
281 ms |
26076 KB |
Output is correct |
63 |
Correct |
262 ms |
26072 KB |
Output is correct |
64 |
Correct |
292 ms |
26104 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
65 ms |
6776 KB |
Output is correct |
67 |
Correct |
271 ms |
26104 KB |
Output is correct |
68 |
Correct |
278 ms |
26104 KB |
Output is correct |
69 |
Correct |
294 ms |
26040 KB |
Output is correct |
70 |
Correct |
0 ms |
256 KB |
Output is correct |
71 |
Correct |
0 ms |
256 KB |
Output is correct |
72 |
Correct |
1 ms |
256 KB |
Output is correct |
73 |
Correct |
66 ms |
6776 KB |
Output is correct |
74 |
Correct |
263 ms |
26104 KB |
Output is correct |
75 |
Correct |
270 ms |
26104 KB |
Output is correct |
76 |
Correct |
265 ms |
26108 KB |
Output is correct |
77 |
Correct |
261 ms |
26104 KB |
Output is correct |
78 |
Correct |
0 ms |
256 KB |
Output is correct |
79 |
Correct |
0 ms |
256 KB |
Output is correct |
80 |
Correct |
5 ms |
1024 KB |
Output is correct |
81 |
Correct |
120 ms |
16092 KB |
Output is correct |
82 |
Correct |
0 ms |
256 KB |
Output is correct |
83 |
Correct |
0 ms |
256 KB |
Output is correct |
84 |
Correct |
0 ms |
256 KB |
Output is correct |
85 |
Correct |
68 ms |
6836 KB |
Output is correct |
86 |
Correct |
127 ms |
16124 KB |
Output is correct |
87 |
Correct |
126 ms |
16088 KB |
Output is correct |
88 |
Correct |
123 ms |
16124 KB |
Output is correct |
89 |
Correct |
118 ms |
16120 KB |
Output is correct |
90 |
Correct |
0 ms |
256 KB |
Output is correct |
91 |
Correct |
0 ms |
256 KB |
Output is correct |
92 |
Correct |
5 ms |
1024 KB |
Output is correct |
93 |
Correct |
121 ms |
16120 KB |
Output is correct |
94 |
Correct |
0 ms |
256 KB |
Output is correct |
95 |
Correct |
1 ms |
256 KB |
Output is correct |
96 |
Correct |
1 ms |
256 KB |
Output is correct |
97 |
Correct |
30 ms |
4352 KB |
Output is correct |
98 |
Correct |
119 ms |
16088 KB |
Output is correct |
99 |
Correct |
120 ms |
16120 KB |
Output is correct |
100 |
Correct |
118 ms |
16120 KB |
Output is correct |
101 |
Correct |
120 ms |
16120 KB |
Output is correct |
102 |
Correct |
126 ms |
16248 KB |
Output is correct |
103 |
Correct |
141 ms |
16120 KB |
Output is correct |
104 |
Correct |
127 ms |
16120 KB |
Output is correct |
105 |
Correct |
124 ms |
16124 KB |
Output is correct |