#include <bits/stdc++.h>
using namespace std;
#define pb push_back
struct dsu {
vector<int> parent, rank;
int size;
dsu(int sz) {
size = sz;
rank.assign(size, 1);
parent.resize(size);
for(int i = 0; i<size; i++) parent[i] = i;
}
int search(int v) {
if(v == parent[v]) return v;
return parent[v] = search(parent[v]);
}
void connect(int v, int u) {
v = search(v);
u = search(u);
if(v == u) return;
if(rank[v]>=rank[u]) parent[u] = v;
else parent[v] = u;
if(rank[v] == rank[u]) rank[v]++;
return;
}
};
void build(std::vector<std::vector<int>> b);
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
bool ctr = 1;
vector<vector<int>> b(n);
for(int i = 0; i<n; i++) b[i].resize(n);
vector<int> a[n];
dsu d = dsu(n);
for(int i = 0; i<n; i++) {
for(int j = 0; j<n; j++) {
if(p[i][j]) d.connect(i, j);
}
}
for(int i = 0; i<n; i++) {
a[d.search(i)].pb(i);
}
for(int i = 0; i<n; i++) {
if(a[i].size()<=1) continue;
int pth = p[a[i][0]][a[i][1]];
for(int ii:a[i]) {
for(int j:a[i]) {
if(ii == j) continue;
if(p[ii][j] != pth) ctr = false;
}
}
for(size_t ii = 1; ii<a[i].size(); ii++) {
b[ii][ii-1] = b[ii-1][ii] = 1;
}
if(pth == 2) b[a[i][0]][a[i].back()] = b[a[i].back()][a[i][0]] = 1;
}
if(ctr) build(b);
return ctr;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
119 ms |
22100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
119 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1112 KB |
Output is correct |
13 |
Correct |
118 ms |
22100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
65 ms |
14248 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
29 ms |
6224 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
119 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1112 KB |
Output is correct |
13 |
Correct |
118 ms |
22100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
65 ms |
14248 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
29 ms |
6224 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
119 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1112 KB |
Output is correct |
13 |
Correct |
118 ms |
22100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
65 ms |
14248 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
29 ms |
6224 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
21 |
Halted |
0 ms |
0 KB |
- |