#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
void build(vector<vector<int>>);
struct dsu {
vector<int> p;
vector<int> sz;
int n;
dsu(int _n) : n(_n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
sz.assign(n, 1);
}
inline int get(int x) {
if (p[x] == x) {
return x;
} else {
return p[x] = get(p[x]);
}
}
inline bool unite(int x, int y) {
x = get(x);
y = get(y);
if (x == y) {
return false;
}
if (sz[x] > sz[y]) {
swap(x, y);
}
p[x] = y;
sz[y] += sz[x];
return true;
}
inline bool same(int x, int y) {
return (get(x) == get(y));
}
};
int construct(vector<vector<int>> p) {
int n = (int) p.size();
dsu uf1(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 1) {
uf1.unite(i, j);
}
}
}
vector<vector<int>> res(n, vector<int>(n));
vector<vector<int>> c(n);
for (int i = 0; i < n; i++) {
c[uf1.get(i)].emplace_back(i);
}
for (int i = 0; i < n; i++) {
for (int j = 1; j < (int) c[i].size(); j++) {
res[c[i][0]][c[i][j]] = res[c[i][j]][c[i][0]] = 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] != p[uf1.get(i)][uf1.get(j)]) {
return 0;
}
}
}
dsu uf2(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (uf1.get(i) == i && uf1.get(j) == j && p[i][j] > 2) {
uf2.unite(i, j);
}
}
}
c = vector<vector<int>>(n);
for (int i = 0; i < n; i++) {
if (uf1.get(i) == i) {
c[uf2.get(i)].emplace_back(i);
}
}
for (int i = 0; i < n; i++) {
int sz = (int) c[i].size();
if (sz == 0 || sz == 1) {
continue;
}
if (sz == 2) {
return 0;
}
for (int j = 0; j < sz; j++) {
res[c[i][j]][c[i][(j + 1) % sz]] = res[c[i][(j + 1) % sz]][c[i][j]] = 1;
}
int z = p[c[i][0]][c[i][1]];
if (z == 3) {
if (sz == 3) {
return 0;
}
res[c[i][0]][c[i][2]] = res[c[i][2]][c[i][0]] = 1;
}
for (int x = 0; x < sz; x++) {
for (int y = x + 1; y < sz; y++) {
if (p[c[i][x]][c[i][y]] != z) {
return 0;
}
}
}
}
build(res);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1088 KB |
Output is correct |
7 |
Correct |
258 ms |
22028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1088 KB |
Output is correct |
7 |
Correct |
258 ms |
22028 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
11 ms |
1168 KB |
Output is correct |
13 |
Correct |
244 ms |
22080 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
98 ms |
12156 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
85 ms |
5772 KB |
Output is correct |
21 |
Correct |
278 ms |
22008 KB |
Output is correct |
22 |
Correct |
207 ms |
22088 KB |
Output is correct |
23 |
Correct |
190 ms |
22012 KB |
Output is correct |
24 |
Correct |
225 ms |
22000 KB |
Output is correct |
25 |
Correct |
72 ms |
12160 KB |
Output is correct |
26 |
Correct |
91 ms |
12168 KB |
Output is correct |
27 |
Correct |
207 ms |
22008 KB |
Output is correct |
28 |
Correct |
177 ms |
22028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
236 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
224 KB |
Too few ways to get from 0 to 1, should be 2 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1088 KB |
Output is correct |
7 |
Correct |
258 ms |
22028 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
11 ms |
1168 KB |
Output is correct |
13 |
Correct |
244 ms |
22080 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
98 ms |
12156 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
85 ms |
5772 KB |
Output is correct |
21 |
Correct |
278 ms |
22008 KB |
Output is correct |
22 |
Correct |
207 ms |
22088 KB |
Output is correct |
23 |
Correct |
190 ms |
22012 KB |
Output is correct |
24 |
Correct |
225 ms |
22000 KB |
Output is correct |
25 |
Correct |
72 ms |
12160 KB |
Output is correct |
26 |
Correct |
91 ms |
12168 KB |
Output is correct |
27 |
Correct |
207 ms |
22008 KB |
Output is correct |
28 |
Correct |
177 ms |
22028 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Incorrect |
1 ms |
236 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1088 KB |
Output is correct |
7 |
Correct |
258 ms |
22028 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
11 ms |
1168 KB |
Output is correct |
13 |
Correct |
244 ms |
22080 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
98 ms |
12156 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
85 ms |
5772 KB |
Output is correct |
21 |
Correct |
278 ms |
22008 KB |
Output is correct |
22 |
Correct |
207 ms |
22088 KB |
Output is correct |
23 |
Correct |
190 ms |
22012 KB |
Output is correct |
24 |
Correct |
225 ms |
22000 KB |
Output is correct |
25 |
Correct |
72 ms |
12160 KB |
Output is correct |
26 |
Correct |
91 ms |
12168 KB |
Output is correct |
27 |
Correct |
207 ms |
22008 KB |
Output is correct |
28 |
Correct |
177 ms |
22028 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Incorrect |
1 ms |
236 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |