#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1001;
struct dsu {
int p[N], sz[N];
void init(int n) {
fill(sz, sz+n, 1);
iota(p, p+n, 0);
}
int get(int u) {
if (u == p[u]) return u;
return p[u] = get(p[u]);
}
bool unite(int u, int v) {
u = get(u), v = get(v);
if (u == v) return 0;
if (sz[u] < sz[v]) swap(u, v);
sz[u] += sz[v];
p[v] = u;
return 1;
}
} D;
bool vis[N];
int n;
vector<int> E;
vector<vector<int>> p;
void dfs(int s) {
vis[s] = 1;
E.pb(s);
for (int i = 0; i < n; ++i) {
if (p[s][D.get(i)] == 2 && !vis[D.get(i)]) dfs(D.get(i));
}
}
int construct(vector<vector<int>> P) {
p = P; n = p.size();
D.init(n);
vector<vector<int>> A(n, vector<int>(n, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (p[i][j] == 1) {
if (D.unite(i, j)) A[i][j] = A[j][i] = 1;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (p[i][j] == 3 || p[i][j] != p[D.get(i)][D.get(j)]) return 0;
}
}
for (int i = 0; i < n; ++i) {
if (!vis[D.get(i)]) {
dfs(D.get(i));
for (int i = 0; i < (int)E.size(); ++i) {
for (int j = 0; j < i; ++j) {
if (p[E[i]][E[j]] != 2) return 0;
}
}
if (E.size() == 1) {
E.clear();
continue;
}
for (int i = 0; i+1 < (int)E.size(); ++i) A[E[i]][E[i+1]] = A[E[i+1]][E[i]] = 1;
A[E.back()][E[0]] = A[E[0]][E.back()] = 1;
E.clear();
}
}
build(A);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1360 KB |
Output is correct |
7 |
Correct |
124 ms |
25996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1360 KB |
Output is correct |
7 |
Correct |
124 ms |
25996 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
9 ms |
1360 KB |
Output is correct |
13 |
Correct |
122 ms |
26148 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
77 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
35 ms |
6944 KB |
Output is correct |
21 |
Correct |
138 ms |
25928 KB |
Output is correct |
22 |
Correct |
133 ms |
26144 KB |
Output is correct |
23 |
Correct |
138 ms |
26148 KB |
Output is correct |
24 |
Correct |
129 ms |
25928 KB |
Output is correct |
25 |
Correct |
63 ms |
16200 KB |
Output is correct |
26 |
Correct |
65 ms |
16200 KB |
Output is correct |
27 |
Correct |
143 ms |
26148 KB |
Output is correct |
28 |
Correct |
133 ms |
25928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 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 |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
32 ms |
6908 KB |
Output is correct |
5 |
Correct |
129 ms |
26384 KB |
Output is correct |
6 |
Correct |
128 ms |
25928 KB |
Output is correct |
7 |
Correct |
140 ms |
25932 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
35 ms |
7408 KB |
Output is correct |
10 |
Correct |
136 ms |
27976 KB |
Output is correct |
11 |
Correct |
135 ms |
27872 KB |
Output is correct |
12 |
Correct |
143 ms |
27976 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
34 ms |
7240 KB |
Output is correct |
17 |
Correct |
130 ms |
27976 KB |
Output is correct |
18 |
Correct |
141 ms |
27976 KB |
Output is correct |
19 |
Correct |
127 ms |
28048 KB |
Output is correct |
20 |
Correct |
134 ms |
27976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1360 KB |
Output is correct |
7 |
Correct |
124 ms |
25996 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
9 ms |
1360 KB |
Output is correct |
13 |
Correct |
122 ms |
26148 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
77 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
35 ms |
6944 KB |
Output is correct |
21 |
Correct |
138 ms |
25928 KB |
Output is correct |
22 |
Correct |
133 ms |
26144 KB |
Output is correct |
23 |
Correct |
138 ms |
26148 KB |
Output is correct |
24 |
Correct |
129 ms |
25928 KB |
Output is correct |
25 |
Correct |
63 ms |
16200 KB |
Output is correct |
26 |
Correct |
65 ms |
16200 KB |
Output is correct |
27 |
Correct |
143 ms |
26148 KB |
Output is correct |
28 |
Correct |
133 ms |
25928 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1360 KB |
Output is correct |
7 |
Correct |
124 ms |
25996 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
9 ms |
1360 KB |
Output is correct |
13 |
Correct |
122 ms |
26148 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
77 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
35 ms |
6944 KB |
Output is correct |
21 |
Correct |
138 ms |
25928 KB |
Output is correct |
22 |
Correct |
133 ms |
26144 KB |
Output is correct |
23 |
Correct |
138 ms |
26148 KB |
Output is correct |
24 |
Correct |
129 ms |
25928 KB |
Output is correct |
25 |
Correct |
63 ms |
16200 KB |
Output is correct |
26 |
Correct |
65 ms |
16200 KB |
Output is correct |
27 |
Correct |
143 ms |
26148 KB |
Output is correct |
28 |
Correct |
133 ms |
25928 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |