#include "supertrees.h"
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <bits/stdc++.h>
#define MEM 222222
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll INF = 2e18;
const ll MOD = 998244353;
ll r[MEM];
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n, 0));
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if(p[i][j]>2) return 0;
for(int i=0; i<n; i++){
ll pp=0;
while(p[i][pp]!=1) pp++;
if(i==pp){
r[i] = 1;
continue;
}
if(p[i]!=p[pp]) return 0;
ans[i][pp] = ans[pp][i] = 1;
}
for(int i=0; i<n; i++){
if(!r[i]) continue;
ll pp=0;
while(p[i][pp]==0) pp++;
for(int j=0; j<n; j++)
if((!p[pp][j] && p[i][j])||(p[pp][j] && !p[i][j])) return 0;
if(pp!=i) continue;
ll pos=i;
for(int j=i+1; j<n; j++)
if(r[j] && p[i][j]) {
ans[j][pos] = ans[pos][j] = 1;
pos = j;
}
if(ans[pos][i]) return 0;
else{
if(pos==i) continue;
ans[i][pos] = ans[pos][i] = 1;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
175 ms |
22204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
175 ms |
22204 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
173 ms |
22308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
85 ms |
12320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
45 ms |
5836 KB |
Output is correct |
21 |
Correct |
172 ms |
22264 KB |
Output is correct |
22 |
Correct |
173 ms |
22216 KB |
Output is correct |
23 |
Correct |
176 ms |
22308 KB |
Output is correct |
24 |
Correct |
173 ms |
22256 KB |
Output is correct |
25 |
Correct |
73 ms |
12324 KB |
Output is correct |
26 |
Correct |
73 ms |
12340 KB |
Output is correct |
27 |
Correct |
177 ms |
22308 KB |
Output is correct |
28 |
Correct |
174 ms |
22200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1220 KB |
Output is correct |
9 |
Correct |
175 ms |
22224 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1216 KB |
Output is correct |
13 |
Correct |
175 ms |
22432 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
81 ms |
12296 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
42 ms |
5844 KB |
Output is correct |
22 |
Correct |
173 ms |
22224 KB |
Output is correct |
23 |
Correct |
173 ms |
22412 KB |
Output is correct |
24 |
Correct |
177 ms |
22312 KB |
Output is correct |
25 |
Correct |
74 ms |
12284 KB |
Output is correct |
26 |
Correct |
79 ms |
12352 KB |
Output is correct |
27 |
Correct |
171 ms |
22220 KB |
Output is correct |
28 |
Correct |
182 ms |
22236 KB |
Output is correct |
29 |
Correct |
77 ms |
12364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
46 ms |
5932 KB |
Output is correct |
5 |
Correct |
169 ms |
22204 KB |
Output is correct |
6 |
Correct |
171 ms |
22312 KB |
Output is correct |
7 |
Correct |
179 ms |
22244 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
50 ms |
5848 KB |
Output is correct |
10 |
Correct |
178 ms |
22304 KB |
Output is correct |
11 |
Correct |
172 ms |
22244 KB |
Output is correct |
12 |
Correct |
180 ms |
22320 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
44 ms |
5836 KB |
Output is correct |
17 |
Correct |
180 ms |
22316 KB |
Output is correct |
18 |
Correct |
176 ms |
22212 KB |
Output is correct |
19 |
Correct |
180 ms |
22208 KB |
Output is correct |
20 |
Correct |
174 ms |
22236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
175 ms |
22204 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
173 ms |
22308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
85 ms |
12320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
45 ms |
5836 KB |
Output is correct |
21 |
Correct |
172 ms |
22264 KB |
Output is correct |
22 |
Correct |
173 ms |
22216 KB |
Output is correct |
23 |
Correct |
176 ms |
22308 KB |
Output is correct |
24 |
Correct |
173 ms |
22256 KB |
Output is correct |
25 |
Correct |
73 ms |
12324 KB |
Output is correct |
26 |
Correct |
73 ms |
12340 KB |
Output is correct |
27 |
Correct |
177 ms |
22308 KB |
Output is correct |
28 |
Correct |
174 ms |
22200 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
304 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1220 KB |
Output is correct |
37 |
Correct |
175 ms |
22224 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1216 KB |
Output is correct |
41 |
Correct |
175 ms |
22432 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
81 ms |
12296 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
42 ms |
5844 KB |
Output is correct |
50 |
Correct |
173 ms |
22224 KB |
Output is correct |
51 |
Correct |
173 ms |
22412 KB |
Output is correct |
52 |
Correct |
177 ms |
22312 KB |
Output is correct |
53 |
Correct |
74 ms |
12284 KB |
Output is correct |
54 |
Correct |
79 ms |
12352 KB |
Output is correct |
55 |
Correct |
171 ms |
22220 KB |
Output is correct |
56 |
Correct |
182 ms |
22236 KB |
Output is correct |
57 |
Correct |
77 ms |
12364 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
81 ms |
12364 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
44 ms |
5888 KB |
Output is correct |
66 |
Correct |
74 ms |
12308 KB |
Output is correct |
67 |
Correct |
76 ms |
12300 KB |
Output is correct |
68 |
Correct |
73 ms |
12364 KB |
Output is correct |
69 |
Correct |
72 ms |
12348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
175 ms |
22204 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
173 ms |
22308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
85 ms |
12320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
45 ms |
5836 KB |
Output is correct |
21 |
Correct |
172 ms |
22264 KB |
Output is correct |
22 |
Correct |
173 ms |
22216 KB |
Output is correct |
23 |
Correct |
176 ms |
22308 KB |
Output is correct |
24 |
Correct |
173 ms |
22256 KB |
Output is correct |
25 |
Correct |
73 ms |
12324 KB |
Output is correct |
26 |
Correct |
73 ms |
12340 KB |
Output is correct |
27 |
Correct |
177 ms |
22308 KB |
Output is correct |
28 |
Correct |
174 ms |
22200 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
304 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1220 KB |
Output is correct |
37 |
Correct |
175 ms |
22224 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1216 KB |
Output is correct |
41 |
Correct |
175 ms |
22432 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
81 ms |
12296 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
42 ms |
5844 KB |
Output is correct |
50 |
Correct |
173 ms |
22224 KB |
Output is correct |
51 |
Correct |
173 ms |
22412 KB |
Output is correct |
52 |
Correct |
177 ms |
22312 KB |
Output is correct |
53 |
Correct |
74 ms |
12284 KB |
Output is correct |
54 |
Correct |
79 ms |
12352 KB |
Output is correct |
55 |
Correct |
171 ms |
22220 KB |
Output is correct |
56 |
Correct |
182 ms |
22236 KB |
Output is correct |
57 |
Correct |
77 ms |
12364 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
304 KB |
Output is correct |
60 |
Correct |
1 ms |
312 KB |
Output is correct |
61 |
Correct |
46 ms |
5932 KB |
Output is correct |
62 |
Correct |
169 ms |
22204 KB |
Output is correct |
63 |
Correct |
171 ms |
22312 KB |
Output is correct |
64 |
Correct |
179 ms |
22244 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
50 ms |
5848 KB |
Output is correct |
67 |
Correct |
178 ms |
22304 KB |
Output is correct |
68 |
Correct |
172 ms |
22244 KB |
Output is correct |
69 |
Correct |
180 ms |
22320 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
44 ms |
5836 KB |
Output is correct |
74 |
Correct |
180 ms |
22316 KB |
Output is correct |
75 |
Correct |
176 ms |
22212 KB |
Output is correct |
76 |
Correct |
180 ms |
22208 KB |
Output is correct |
77 |
Correct |
174 ms |
22236 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
852 KB |
Output is correct |
81 |
Correct |
81 ms |
12364 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
44 ms |
5888 KB |
Output is correct |
86 |
Correct |
74 ms |
12308 KB |
Output is correct |
87 |
Correct |
76 ms |
12300 KB |
Output is correct |
88 |
Correct |
73 ms |
12364 KB |
Output is correct |
89 |
Correct |
72 ms |
12348 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
852 KB |
Output is correct |
93 |
Correct |
76 ms |
12320 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
19 ms |
3372 KB |
Output is correct |
98 |
Correct |
75 ms |
12352 KB |
Output is correct |
99 |
Correct |
72 ms |
12300 KB |
Output is correct |
100 |
Correct |
78 ms |
12296 KB |
Output is correct |
101 |
Correct |
76 ms |
12448 KB |
Output is correct |
102 |
Correct |
77 ms |
12368 KB |
Output is correct |
103 |
Correct |
79 ms |
12364 KB |
Output is correct |
104 |
Correct |
81 ms |
12324 KB |
Output is correct |
105 |
Correct |
81 ms |
12312 KB |
Output is correct |