#include "supertrees.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
using namespace std;
vector<vector<int>> ans;
int n;
struct dsu {
vector<int> par;
vector<vector<int>> nds;
void init(int n) {
par.assign(n, -1);
nds.assign(n, vector<int>());
Loop (i,0,n)
nds[i].push_back(i);
}
int rt(int v) { return par[v] == -1? v: (par[v] = rt(par[v])); }
bool same(int v, int u) { return rt(v) == rt(u); }
bool unite(int v, int u) {
v = rt(v);
u = rt(u);
if (v == u)
return 0;
if (nds[v].size() < nds[u].size())
swap(v, u);
par[u] = v;
nds[v].insert(nds[v].end(), nds[u].begin(), nds[u].end());
vector<int> tmp;
tmp.swap(nds[u]);
return 1;
}
};
int construct(std::vector<std::vector<int>> p) {
n = p.size();
ans.assign(n, vector<int>(n, 0));
Loop (i,0,n) Loop (j,i+1,n) {
if (p[i][j] == 3)
return 0;
}
dsu dsu1;
dsu1.init(n);
Loop (i,0,n) Loop (j,i+1,n) {
if (p[i][j] == 1 && dsu1.unite(i, j))
ans[i][j] = ans[j][i] = 1;
}
Loop (i,0,n) Loop (j,i+1,n) {
if (p[i][j] != 1 && dsu1.same(i, j))
return 0;
}
dsu dsu2;
dsu2.init(n);
Loop (i,0,n) Loop (j,i+1,n) {
if (p[i][j] != 2)
continue;
if (dsu1.same(i, j))
return 0;
int x = dsu1.rt(i);
int y = dsu1.rt(j);
dsu2.unite(x, y);
}
Loop (i,0,n) Loop (j,i+1,n) {
int x = dsu1.rt(i);
int y = dsu1.rt(j);
if (p[i][j] == 0 && dsu2.same(x, y))
return 0;
}
Loop (i,0,n) {
if (dsu2.par[i] != -1)
continue;
int sz = dsu2.nds[i].size();
if (sz <= 1)
continue;
Loop (j,0,sz) {
int x = dsu2.nds[i][j];
int y = dsu2.nds[i][(j+1)%sz];
ans[x][y] = ans[y][x] = 1;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
170 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
170 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
9 ms |
1236 KB |
Output is correct |
13 |
Correct |
164 ms |
24048 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
828 KB |
Output is correct |
17 |
Correct |
89 ms |
14064 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
6208 KB |
Output is correct |
21 |
Correct |
167 ms |
24076 KB |
Output is correct |
22 |
Correct |
156 ms |
24004 KB |
Output is correct |
23 |
Correct |
164 ms |
24028 KB |
Output is correct |
24 |
Correct |
155 ms |
24060 KB |
Output is correct |
25 |
Correct |
63 ms |
14080 KB |
Output is correct |
26 |
Correct |
61 ms |
14076 KB |
Output is correct |
27 |
Correct |
167 ms |
24056 KB |
Output is correct |
28 |
Correct |
158 ms |
24148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 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 |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
40 ms |
6304 KB |
Output is correct |
5 |
Correct |
163 ms |
24056 KB |
Output is correct |
6 |
Correct |
157 ms |
24032 KB |
Output is correct |
7 |
Correct |
166 ms |
24052 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
47 ms |
6324 KB |
Output is correct |
10 |
Correct |
176 ms |
24028 KB |
Output is correct |
11 |
Correct |
165 ms |
24088 KB |
Output is correct |
12 |
Correct |
164 ms |
24008 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
39 ms |
6316 KB |
Output is correct |
17 |
Correct |
156 ms |
24068 KB |
Output is correct |
18 |
Correct |
161 ms |
23988 KB |
Output is correct |
19 |
Correct |
174 ms |
24024 KB |
Output is correct |
20 |
Correct |
158 ms |
24012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
170 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
9 ms |
1236 KB |
Output is correct |
13 |
Correct |
164 ms |
24048 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
828 KB |
Output is correct |
17 |
Correct |
89 ms |
14064 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
6208 KB |
Output is correct |
21 |
Correct |
167 ms |
24076 KB |
Output is correct |
22 |
Correct |
156 ms |
24004 KB |
Output is correct |
23 |
Correct |
164 ms |
24028 KB |
Output is correct |
24 |
Correct |
155 ms |
24060 KB |
Output is correct |
25 |
Correct |
63 ms |
14080 KB |
Output is correct |
26 |
Correct |
61 ms |
14076 KB |
Output is correct |
27 |
Correct |
167 ms |
24056 KB |
Output is correct |
28 |
Correct |
158 ms |
24148 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
170 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
9 ms |
1236 KB |
Output is correct |
13 |
Correct |
164 ms |
24048 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
828 KB |
Output is correct |
17 |
Correct |
89 ms |
14064 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
6208 KB |
Output is correct |
21 |
Correct |
167 ms |
24076 KB |
Output is correct |
22 |
Correct |
156 ms |
24004 KB |
Output is correct |
23 |
Correct |
164 ms |
24028 KB |
Output is correct |
24 |
Correct |
155 ms |
24060 KB |
Output is correct |
25 |
Correct |
63 ms |
14080 KB |
Output is correct |
26 |
Correct |
61 ms |
14076 KB |
Output is correct |
27 |
Correct |
167 ms |
24056 KB |
Output is correct |
28 |
Correct |
158 ms |
24148 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |