//In the name of God
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Mp make_pair
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define Sz(x) ll((x).size())
ll v1[maxn], v2[maxn], c[maxn], cc[maxn], t, tt;
vector<ll> vec[maxn];
int construct(vector<vector<int>> p) {
int n = Sz(p);
vector<vector<int>> answer(n);
for(ll i = 0; i < n; i++){
answer[i].resize(n);
for(ll j = 0; j < n; j++){
if(p[i][j] == 3) return 0;
}
}
for(ll i = 0; i < n; i++){
if(v2[i]) continue;
if(!v1[i]) c[i] = t++;
vec[c[i]].pb(i);
if(v2[i]) continue;
cc[i] = tt++;
for(ll j = 0; j < n; j++){
if(i == j || p[i][j] == 0) continue;
v1[j] = 1;
c[j] = c[i];
if(p[i][j] == 1){
v2[j] = 1;
cc[j] = cc[i];
answer[i][j] = 1;
answer[j][i] = 1;
}
}
v1[i] = 1;
v2[i] = 1;
}
for(ll i = 0; i < n; i++){
for(ll j = 0; j < n; j++){
if((p[i][j] > 0) != (c[i] == c[j])) return 0;
if((p[i][j] == 1) != (cc[i] == cc[j])) return 0;
}
}
for(ll i = 0; i < t; i++){
if(Sz(vec[i]) == 2) return 0;
if(Sz(vec[i]) < 3) continue;
for(ll j = 0; j + 1 < Sz(vec[i]); j++){
answer[vec[i][j]][vec[i][j + 1]] = 1;
answer[vec[i][j + 1]][vec[i][j]] = 1;
}
answer[vec[i][0]][vec[i].back()] = 1;
answer[vec[i].back()][vec[i][0]] = 1;
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4996 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5000 KB |
Output is correct |
5 |
Correct |
3 ms |
4996 KB |
Output is correct |
6 |
Correct |
12 ms |
5916 KB |
Output is correct |
7 |
Correct |
237 ms |
27472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4996 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5000 KB |
Output is correct |
5 |
Correct |
3 ms |
4996 KB |
Output is correct |
6 |
Correct |
12 ms |
5916 KB |
Output is correct |
7 |
Correct |
237 ms |
27472 KB |
Output is correct |
8 |
Correct |
4 ms |
5004 KB |
Output is correct |
9 |
Correct |
4 ms |
4996 KB |
Output is correct |
10 |
Correct |
5 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
5020 KB |
Output is correct |
12 |
Correct |
16 ms |
5960 KB |
Output is correct |
13 |
Correct |
228 ms |
27580 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
8 ms |
5580 KB |
Output is correct |
17 |
Correct |
102 ms |
17616 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4976 KB |
Output is correct |
20 |
Correct |
60 ms |
10956 KB |
Output is correct |
21 |
Correct |
224 ms |
27512 KB |
Output is correct |
22 |
Correct |
228 ms |
27464 KB |
Output is correct |
23 |
Correct |
258 ms |
27472 KB |
Output is correct |
24 |
Correct |
284 ms |
27784 KB |
Output is correct |
25 |
Correct |
105 ms |
17604 KB |
Output is correct |
26 |
Correct |
98 ms |
17656 KB |
Output is correct |
27 |
Correct |
229 ms |
27452 KB |
Output is correct |
28 |
Correct |
231 ms |
27592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4928 KB |
Output is correct |
2 |
Correct |
4 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
5068 KB |
Output is correct |
4 |
Correct |
3 ms |
4996 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4996 KB |
Output is correct |
7 |
Correct |
5 ms |
4996 KB |
Output is correct |
8 |
Correct |
15 ms |
5952 KB |
Output is correct |
9 |
Correct |
228 ms |
27536 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
13 ms |
5964 KB |
Output is correct |
13 |
Correct |
236 ms |
27556 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
11 ms |
5520 KB |
Output is correct |
17 |
Correct |
112 ms |
17580 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
60 ms |
10956 KB |
Output is correct |
22 |
Correct |
280 ms |
27560 KB |
Output is correct |
23 |
Correct |
222 ms |
27528 KB |
Output is correct |
24 |
Correct |
243 ms |
27552 KB |
Output is correct |
25 |
Correct |
97 ms |
17604 KB |
Output is correct |
26 |
Correct |
102 ms |
17576 KB |
Output is correct |
27 |
Correct |
228 ms |
27620 KB |
Output is correct |
28 |
Correct |
285 ms |
27548 KB |
Output is correct |
29 |
Correct |
112 ms |
17652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
64 ms |
10996 KB |
Output is correct |
5 |
Correct |
224 ms |
27560 KB |
Output is correct |
6 |
Correct |
233 ms |
27460 KB |
Output is correct |
7 |
Correct |
239 ms |
27556 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
62 ms |
10988 KB |
Output is correct |
10 |
Correct |
233 ms |
27492 KB |
Output is correct |
11 |
Correct |
229 ms |
27600 KB |
Output is correct |
12 |
Correct |
236 ms |
27460 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
5004 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
82 ms |
10944 KB |
Output is correct |
17 |
Correct |
234 ms |
27492 KB |
Output is correct |
18 |
Correct |
237 ms |
27568 KB |
Output is correct |
19 |
Correct |
238 ms |
27480 KB |
Output is correct |
20 |
Correct |
228 ms |
27524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4996 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5000 KB |
Output is correct |
5 |
Correct |
3 ms |
4996 KB |
Output is correct |
6 |
Correct |
12 ms |
5916 KB |
Output is correct |
7 |
Correct |
237 ms |
27472 KB |
Output is correct |
8 |
Correct |
4 ms |
5004 KB |
Output is correct |
9 |
Correct |
4 ms |
4996 KB |
Output is correct |
10 |
Correct |
5 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
5020 KB |
Output is correct |
12 |
Correct |
16 ms |
5960 KB |
Output is correct |
13 |
Correct |
228 ms |
27580 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
8 ms |
5580 KB |
Output is correct |
17 |
Correct |
102 ms |
17616 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4976 KB |
Output is correct |
20 |
Correct |
60 ms |
10956 KB |
Output is correct |
21 |
Correct |
224 ms |
27512 KB |
Output is correct |
22 |
Correct |
228 ms |
27464 KB |
Output is correct |
23 |
Correct |
258 ms |
27472 KB |
Output is correct |
24 |
Correct |
284 ms |
27784 KB |
Output is correct |
25 |
Correct |
105 ms |
17604 KB |
Output is correct |
26 |
Correct |
98 ms |
17656 KB |
Output is correct |
27 |
Correct |
229 ms |
27452 KB |
Output is correct |
28 |
Correct |
231 ms |
27592 KB |
Output is correct |
29 |
Correct |
3 ms |
4928 KB |
Output is correct |
30 |
Correct |
4 ms |
5000 KB |
Output is correct |
31 |
Correct |
3 ms |
5068 KB |
Output is correct |
32 |
Correct |
3 ms |
4996 KB |
Output is correct |
33 |
Correct |
4 ms |
4940 KB |
Output is correct |
34 |
Correct |
4 ms |
4996 KB |
Output is correct |
35 |
Correct |
5 ms |
4996 KB |
Output is correct |
36 |
Correct |
15 ms |
5952 KB |
Output is correct |
37 |
Correct |
228 ms |
27536 KB |
Output is correct |
38 |
Correct |
3 ms |
4940 KB |
Output is correct |
39 |
Correct |
4 ms |
4940 KB |
Output is correct |
40 |
Correct |
13 ms |
5964 KB |
Output is correct |
41 |
Correct |
236 ms |
27556 KB |
Output is correct |
42 |
Correct |
4 ms |
4940 KB |
Output is correct |
43 |
Correct |
3 ms |
4940 KB |
Output is correct |
44 |
Correct |
11 ms |
5520 KB |
Output is correct |
45 |
Correct |
112 ms |
17580 KB |
Output is correct |
46 |
Correct |
4 ms |
4992 KB |
Output is correct |
47 |
Correct |
3 ms |
4940 KB |
Output is correct |
48 |
Correct |
4 ms |
4940 KB |
Output is correct |
49 |
Correct |
60 ms |
10956 KB |
Output is correct |
50 |
Correct |
280 ms |
27560 KB |
Output is correct |
51 |
Correct |
222 ms |
27528 KB |
Output is correct |
52 |
Correct |
243 ms |
27552 KB |
Output is correct |
53 |
Correct |
97 ms |
17604 KB |
Output is correct |
54 |
Correct |
102 ms |
17576 KB |
Output is correct |
55 |
Correct |
228 ms |
27620 KB |
Output is correct |
56 |
Correct |
285 ms |
27548 KB |
Output is correct |
57 |
Correct |
112 ms |
17652 KB |
Output is correct |
58 |
Correct |
3 ms |
4940 KB |
Output is correct |
59 |
Correct |
3 ms |
4900 KB |
Output is correct |
60 |
Correct |
7 ms |
5580 KB |
Output is correct |
61 |
Correct |
110 ms |
17656 KB |
Output is correct |
62 |
Correct |
4 ms |
4940 KB |
Output is correct |
63 |
Correct |
4 ms |
4996 KB |
Output is correct |
64 |
Correct |
4 ms |
4940 KB |
Output is correct |
65 |
Correct |
63 ms |
10976 KB |
Output is correct |
66 |
Correct |
106 ms |
17736 KB |
Output is correct |
67 |
Correct |
97 ms |
17604 KB |
Output is correct |
68 |
Correct |
111 ms |
17532 KB |
Output is correct |
69 |
Correct |
99 ms |
17652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4996 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5000 KB |
Output is correct |
5 |
Correct |
3 ms |
4996 KB |
Output is correct |
6 |
Correct |
12 ms |
5916 KB |
Output is correct |
7 |
Correct |
237 ms |
27472 KB |
Output is correct |
8 |
Correct |
4 ms |
5004 KB |
Output is correct |
9 |
Correct |
4 ms |
4996 KB |
Output is correct |
10 |
Correct |
5 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
5020 KB |
Output is correct |
12 |
Correct |
16 ms |
5960 KB |
Output is correct |
13 |
Correct |
228 ms |
27580 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
8 ms |
5580 KB |
Output is correct |
17 |
Correct |
102 ms |
17616 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4976 KB |
Output is correct |
20 |
Correct |
60 ms |
10956 KB |
Output is correct |
21 |
Correct |
224 ms |
27512 KB |
Output is correct |
22 |
Correct |
228 ms |
27464 KB |
Output is correct |
23 |
Correct |
258 ms |
27472 KB |
Output is correct |
24 |
Correct |
284 ms |
27784 KB |
Output is correct |
25 |
Correct |
105 ms |
17604 KB |
Output is correct |
26 |
Correct |
98 ms |
17656 KB |
Output is correct |
27 |
Correct |
229 ms |
27452 KB |
Output is correct |
28 |
Correct |
231 ms |
27592 KB |
Output is correct |
29 |
Correct |
3 ms |
4928 KB |
Output is correct |
30 |
Correct |
4 ms |
5000 KB |
Output is correct |
31 |
Correct |
3 ms |
5068 KB |
Output is correct |
32 |
Correct |
3 ms |
4996 KB |
Output is correct |
33 |
Correct |
4 ms |
4940 KB |
Output is correct |
34 |
Correct |
4 ms |
4996 KB |
Output is correct |
35 |
Correct |
5 ms |
4996 KB |
Output is correct |
36 |
Correct |
15 ms |
5952 KB |
Output is correct |
37 |
Correct |
228 ms |
27536 KB |
Output is correct |
38 |
Correct |
3 ms |
4940 KB |
Output is correct |
39 |
Correct |
4 ms |
4940 KB |
Output is correct |
40 |
Correct |
13 ms |
5964 KB |
Output is correct |
41 |
Correct |
236 ms |
27556 KB |
Output is correct |
42 |
Correct |
4 ms |
4940 KB |
Output is correct |
43 |
Correct |
3 ms |
4940 KB |
Output is correct |
44 |
Correct |
11 ms |
5520 KB |
Output is correct |
45 |
Correct |
112 ms |
17580 KB |
Output is correct |
46 |
Correct |
4 ms |
4992 KB |
Output is correct |
47 |
Correct |
3 ms |
4940 KB |
Output is correct |
48 |
Correct |
4 ms |
4940 KB |
Output is correct |
49 |
Correct |
60 ms |
10956 KB |
Output is correct |
50 |
Correct |
280 ms |
27560 KB |
Output is correct |
51 |
Correct |
222 ms |
27528 KB |
Output is correct |
52 |
Correct |
243 ms |
27552 KB |
Output is correct |
53 |
Correct |
97 ms |
17604 KB |
Output is correct |
54 |
Correct |
102 ms |
17576 KB |
Output is correct |
55 |
Correct |
228 ms |
27620 KB |
Output is correct |
56 |
Correct |
285 ms |
27548 KB |
Output is correct |
57 |
Correct |
112 ms |
17652 KB |
Output is correct |
58 |
Correct |
3 ms |
4940 KB |
Output is correct |
59 |
Correct |
4 ms |
4940 KB |
Output is correct |
60 |
Correct |
5 ms |
4940 KB |
Output is correct |
61 |
Correct |
64 ms |
10996 KB |
Output is correct |
62 |
Correct |
224 ms |
27560 KB |
Output is correct |
63 |
Correct |
233 ms |
27460 KB |
Output is correct |
64 |
Correct |
239 ms |
27556 KB |
Output is correct |
65 |
Correct |
3 ms |
4940 KB |
Output is correct |
66 |
Correct |
62 ms |
10988 KB |
Output is correct |
67 |
Correct |
233 ms |
27492 KB |
Output is correct |
68 |
Correct |
229 ms |
27600 KB |
Output is correct |
69 |
Correct |
236 ms |
27460 KB |
Output is correct |
70 |
Correct |
4 ms |
4940 KB |
Output is correct |
71 |
Correct |
4 ms |
5004 KB |
Output is correct |
72 |
Correct |
4 ms |
4940 KB |
Output is correct |
73 |
Correct |
82 ms |
10944 KB |
Output is correct |
74 |
Correct |
234 ms |
27492 KB |
Output is correct |
75 |
Correct |
237 ms |
27568 KB |
Output is correct |
76 |
Correct |
238 ms |
27480 KB |
Output is correct |
77 |
Correct |
228 ms |
27524 KB |
Output is correct |
78 |
Correct |
3 ms |
4940 KB |
Output is correct |
79 |
Correct |
3 ms |
4900 KB |
Output is correct |
80 |
Correct |
7 ms |
5580 KB |
Output is correct |
81 |
Correct |
110 ms |
17656 KB |
Output is correct |
82 |
Correct |
4 ms |
4940 KB |
Output is correct |
83 |
Correct |
4 ms |
4996 KB |
Output is correct |
84 |
Correct |
4 ms |
4940 KB |
Output is correct |
85 |
Correct |
63 ms |
10976 KB |
Output is correct |
86 |
Correct |
106 ms |
17736 KB |
Output is correct |
87 |
Correct |
97 ms |
17604 KB |
Output is correct |
88 |
Correct |
111 ms |
17532 KB |
Output is correct |
89 |
Correct |
99 ms |
17652 KB |
Output is correct |
90 |
Correct |
3 ms |
4940 KB |
Output is correct |
91 |
Correct |
4 ms |
4940 KB |
Output is correct |
92 |
Correct |
9 ms |
5324 KB |
Output is correct |
93 |
Correct |
96 ms |
13636 KB |
Output is correct |
94 |
Correct |
4 ms |
4940 KB |
Output is correct |
95 |
Correct |
4 ms |
5040 KB |
Output is correct |
96 |
Correct |
3 ms |
4940 KB |
Output is correct |
97 |
Correct |
27 ms |
7492 KB |
Output is correct |
98 |
Correct |
95 ms |
13824 KB |
Output is correct |
99 |
Correct |
95 ms |
14252 KB |
Output is correct |
100 |
Correct |
93 ms |
14004 KB |
Output is correct |
101 |
Correct |
94 ms |
14996 KB |
Output is correct |
102 |
Correct |
115 ms |
13768 KB |
Output is correct |
103 |
Correct |
98 ms |
13804 KB |
Output is correct |
104 |
Correct |
91 ms |
13684 KB |
Output is correct |
105 |
Correct |
97 ms |
13636 KB |
Output is correct |