#include <bits/stdc++.h>
#include "supertrees.h"
#define rall(s) s.end(), s.begin()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define pb push_back
#define vt vector
#define s second
#define f first
#define nl '\n'
using ll = long long;
//using pii = pair<int, int>;
//using pll = pair<ll, ll>;
using namespace std;
const int N = 1e5;
int pr[N], l[N];
int get(int x) {
if (pr[x] == x) return x;
return pr[x] = get(pr[x]);
}
void unite(int a, int b) {
a = get(a);
b = get(b);
if (a == b) return;
if (l[a] > l[b]) swap(a, b);
pr[a] = b;
l[b] += l[a];
}
int construct(vt<vt<int>> p) {
int n = sz(p);
bool ok = 0;
vt<vt<int>> b;
for (int i = 0; i < n; i++) {
pr[i] = i, l[i] = 1;
}
for (int i = 0; i < n; i++) {
vt<int> s;
s.resize(n);
b.pb(s);
for (int j = i + 1; j < n; j++) {
if (p[i][j]) {
unite(i, j);
}
if (p[i][j] == 2) ok = 1;
}
}
vt<int> was(n);
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 (was[i]) continue;
int x = get(i);
int lst = i;
was[i] = 1;
for (int j = i + 1; j < n; j++) {
if (get(j) == x) {
was[j] = 1;
b[lst][j] = b[j][lst] = 1;
lst = j;
}
}
if (ok && lst != i) {
if (b[i][lst] == 1) return 0;
b[lst][i] = b[i][lst] = 1;
}
}
build(b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
190 ms |
22108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
190 ms |
22108 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1168 KB |
Output is correct |
13 |
Correct |
175 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12048 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5772 KB |
Output is correct |
21 |
Correct |
188 ms |
22044 KB |
Output is correct |
22 |
Correct |
231 ms |
22028 KB |
Output is correct |
23 |
Correct |
204 ms |
22072 KB |
Output is correct |
24 |
Correct |
172 ms |
22032 KB |
Output is correct |
25 |
Correct |
72 ms |
12048 KB |
Output is correct |
26 |
Correct |
74 ms |
12108 KB |
Output is correct |
27 |
Correct |
177 ms |
22040 KB |
Output is correct |
28 |
Correct |
174 ms |
22060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
8 ms |
1216 KB |
Output is correct |
9 |
Correct |
180 ms |
23928 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1220 KB |
Output is correct |
13 |
Correct |
172 ms |
23952 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
83 ms |
14084 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
46 ms |
6256 KB |
Output is correct |
22 |
Correct |
180 ms |
24052 KB |
Output is correct |
23 |
Correct |
172 ms |
24012 KB |
Output is correct |
24 |
Correct |
178 ms |
23936 KB |
Output is correct |
25 |
Correct |
73 ms |
14080 KB |
Output is correct |
26 |
Correct |
72 ms |
14080 KB |
Output is correct |
27 |
Correct |
171 ms |
23932 KB |
Output is correct |
28 |
Correct |
178 ms |
24012 KB |
Output is correct |
29 |
Correct |
73 ms |
14080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
43 ms |
5732 KB |
Output is correct |
5 |
Correct |
175 ms |
22028 KB |
Output is correct |
6 |
Correct |
174 ms |
22056 KB |
Output is correct |
7 |
Correct |
179 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
43 ms |
5708 KB |
Output is correct |
10 |
Correct |
175 ms |
21992 KB |
Output is correct |
11 |
Correct |
170 ms |
22056 KB |
Output is correct |
12 |
Correct |
187 ms |
22204 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
190 ms |
22108 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1168 KB |
Output is correct |
13 |
Correct |
175 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12048 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5772 KB |
Output is correct |
21 |
Correct |
188 ms |
22044 KB |
Output is correct |
22 |
Correct |
231 ms |
22028 KB |
Output is correct |
23 |
Correct |
204 ms |
22072 KB |
Output is correct |
24 |
Correct |
172 ms |
22032 KB |
Output is correct |
25 |
Correct |
72 ms |
12048 KB |
Output is correct |
26 |
Correct |
74 ms |
12108 KB |
Output is correct |
27 |
Correct |
177 ms |
22040 KB |
Output is correct |
28 |
Correct |
174 ms |
22060 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
312 KB |
Output is correct |
34 |
Correct |
1 ms |
308 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
8 ms |
1216 KB |
Output is correct |
37 |
Correct |
180 ms |
23928 KB |
Output is correct |
38 |
Correct |
1 ms |
312 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1220 KB |
Output is correct |
41 |
Correct |
172 ms |
23952 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
308 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
83 ms |
14084 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
312 KB |
Output is correct |
49 |
Correct |
46 ms |
6256 KB |
Output is correct |
50 |
Correct |
180 ms |
24052 KB |
Output is correct |
51 |
Correct |
172 ms |
24012 KB |
Output is correct |
52 |
Correct |
178 ms |
23936 KB |
Output is correct |
53 |
Correct |
73 ms |
14080 KB |
Output is correct |
54 |
Correct |
72 ms |
14080 KB |
Output is correct |
55 |
Correct |
171 ms |
23932 KB |
Output is correct |
56 |
Correct |
178 ms |
24012 KB |
Output is correct |
57 |
Correct |
73 ms |
14080 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
308 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
78 ms |
14088 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 9, should be 1 found no less than 2 |
64 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
190 ms |
22108 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1168 KB |
Output is correct |
13 |
Correct |
175 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12048 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5772 KB |
Output is correct |
21 |
Correct |
188 ms |
22044 KB |
Output is correct |
22 |
Correct |
231 ms |
22028 KB |
Output is correct |
23 |
Correct |
204 ms |
22072 KB |
Output is correct |
24 |
Correct |
172 ms |
22032 KB |
Output is correct |
25 |
Correct |
72 ms |
12048 KB |
Output is correct |
26 |
Correct |
74 ms |
12108 KB |
Output is correct |
27 |
Correct |
177 ms |
22040 KB |
Output is correct |
28 |
Correct |
174 ms |
22060 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
312 KB |
Output is correct |
34 |
Correct |
1 ms |
308 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
8 ms |
1216 KB |
Output is correct |
37 |
Correct |
180 ms |
23928 KB |
Output is correct |
38 |
Correct |
1 ms |
312 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1220 KB |
Output is correct |
41 |
Correct |
172 ms |
23952 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
308 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
83 ms |
14084 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
312 KB |
Output is correct |
49 |
Correct |
46 ms |
6256 KB |
Output is correct |
50 |
Correct |
180 ms |
24052 KB |
Output is correct |
51 |
Correct |
172 ms |
24012 KB |
Output is correct |
52 |
Correct |
178 ms |
23936 KB |
Output is correct |
53 |
Correct |
73 ms |
14080 KB |
Output is correct |
54 |
Correct |
72 ms |
14080 KB |
Output is correct |
55 |
Correct |
171 ms |
23932 KB |
Output is correct |
56 |
Correct |
178 ms |
24012 KB |
Output is correct |
57 |
Correct |
73 ms |
14080 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
43 ms |
5732 KB |
Output is correct |
62 |
Correct |
175 ms |
22028 KB |
Output is correct |
63 |
Correct |
174 ms |
22056 KB |
Output is correct |
64 |
Correct |
179 ms |
22020 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
43 ms |
5708 KB |
Output is correct |
67 |
Correct |
175 ms |
21992 KB |
Output is correct |
68 |
Correct |
170 ms |
22056 KB |
Output is correct |
69 |
Correct |
187 ms |
22204 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
72 |
Halted |
0 ms |
0 KB |
- |