#include "supertrees.h"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 1000;
const int BASE = 7;
const int MOD = 998244353;
vector<vector<int>> answer;
inline void add_edge(int a, int b) {
answer[a][b] = answer[b][a] = 1;
}
struct DSU {
int p[MAXN + 10];
void init() {
memset(p, -1, sizeof(p));
}
int find(int n) {
if(p[n] < 0) return n;
return p[n] = find(p[n]);
}
bool uni(int a, int b) {
a = find(a); b = find(b);
if(a == b) return false;
p[b] = a;
return true;
}
bool same(int a, int b) {
return find(a) == find(b);
}
bool lead(int n) {
return p[n] < 0;
}
} dsu;
bool solve_sun(vector<vector<int>> &p, vector<int> &cc) {
int n = sz(cc);
// leave p[i][j] = 1 or 2 only
for(auto &v1:cc) for(auto &v2:cc) if(v1 != v2) {
if(p[v1][v2] == 0) return false;
}
// phase 1: collect groups of tantacles
vector<pii> vh; // {hash, index}
For(i, 0, n - 1) {
int h = 0;
For(j, 0, n - 1) {
h = (h * BASE + p[cc[i]][cc[j]]) % MOD;
}
vh.eb(h, cc[i]);
}
sort(all(vh));
vector<vector<int>> g;
g.eb();
g.back().eb(vh[0].S);
For(i, 1, n - 1) {
if(vh[i].F != vh[i - 1].F) g.eb();
g.back().eb(vh[i].S);
}
// phase 2-1: link cycle
For(i, 1, sz(g) - 1) {
add_edge(g[i].back(), g[i - 1].back());
}
add_edge(g.front().back(), g.back().back());
// phase 2-2: link tantacles
for(auto &i:g) {
int rt = i.back();
i.pop_back();
for(auto &j:i) {
add_edge(j, rt);
}
}
return true;
}
int construct(vector<vector<int>> p) {
int n = sz(p);
For(i, 0, n - 1) For(j, 0, n - 1) if(p[i][j] == 3) return 0;
answer = vector<vector<int>>(n, vector<int>(n, 0));
// phase 1: find all CC
dsu.init();
For(i, 0, n - 1) For(j, 0, n - 1) {
if(p[i][j]) dsu.uni(i, j);
}
vector<vector<int>> vcc;
For(i, 0, n - 1) if(dsu.lead(i)) {
vcc.eb();
For(j, 0, n - 1) if(dsu.same(i, j)) {
vcc.back().eb(j);
}
}
// phase 2: solve for each CC
for(vector<int> &cc:vcc) if(sz(cc) > 1) {
int mask = 0;
for(auto &v1:cc) for(auto &v2:cc) if(v1 != v2) {
mask |= (1 << p[v1][v2]);
}
if(mask & 1) return 0;
if(mask == 2) {
int rt = cc.back();
cc.pop_back();
for(auto &i:cc) {
add_edge(i, rt);
}
} else {
if(!solve_sun(p, cc)) return 0;
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
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 |
1160 KB |
Output is correct |
7 |
Correct |
156 ms |
21952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1160 KB |
Output is correct |
7 |
Correct |
156 ms |
21952 KB |
Output is correct |
8 |
Correct |
0 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 |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
156 ms |
22092 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
74 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
5732 KB |
Output is correct |
21 |
Correct |
157 ms |
21984 KB |
Output is correct |
22 |
Correct |
159 ms |
21960 KB |
Output is correct |
23 |
Correct |
165 ms |
22020 KB |
Output is correct |
24 |
Correct |
158 ms |
22020 KB |
Output is correct |
25 |
Correct |
67 ms |
12036 KB |
Output is correct |
26 |
Correct |
68 ms |
12048 KB |
Output is correct |
27 |
Correct |
164 ms |
22028 KB |
Output is correct |
28 |
Correct |
157 ms |
22060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
Incorrect |
1 ms |
288 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 |
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 |
39 ms |
5708 KB |
Output is correct |
5 |
Correct |
173 ms |
21940 KB |
Output is correct |
6 |
Correct |
155 ms |
21964 KB |
Output is correct |
7 |
Correct |
161 ms |
22020 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
39 ms |
5724 KB |
Output is correct |
10 |
Correct |
156 ms |
22020 KB |
Output is correct |
11 |
Correct |
158 ms |
22036 KB |
Output is correct |
12 |
Correct |
165 ms |
22052 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
39 ms |
5716 KB |
Output is correct |
17 |
Correct |
156 ms |
21968 KB |
Output is correct |
18 |
Correct |
158 ms |
21964 KB |
Output is correct |
19 |
Correct |
157 ms |
22032 KB |
Output is correct |
20 |
Correct |
156 ms |
22036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1160 KB |
Output is correct |
7 |
Correct |
156 ms |
21952 KB |
Output is correct |
8 |
Correct |
0 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 |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
156 ms |
22092 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
74 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
5732 KB |
Output is correct |
21 |
Correct |
157 ms |
21984 KB |
Output is correct |
22 |
Correct |
159 ms |
21960 KB |
Output is correct |
23 |
Correct |
165 ms |
22020 KB |
Output is correct |
24 |
Correct |
158 ms |
22020 KB |
Output is correct |
25 |
Correct |
67 ms |
12036 KB |
Output is correct |
26 |
Correct |
68 ms |
12048 KB |
Output is correct |
27 |
Correct |
164 ms |
22028 KB |
Output is correct |
28 |
Correct |
157 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 |
Incorrect |
1 ms |
288 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1160 KB |
Output is correct |
7 |
Correct |
156 ms |
21952 KB |
Output is correct |
8 |
Correct |
0 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 |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
156 ms |
22092 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
74 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
5732 KB |
Output is correct |
21 |
Correct |
157 ms |
21984 KB |
Output is correct |
22 |
Correct |
159 ms |
21960 KB |
Output is correct |
23 |
Correct |
165 ms |
22020 KB |
Output is correct |
24 |
Correct |
158 ms |
22020 KB |
Output is correct |
25 |
Correct |
67 ms |
12036 KB |
Output is correct |
26 |
Correct |
68 ms |
12048 KB |
Output is correct |
27 |
Correct |
164 ms |
22028 KB |
Output is correct |
28 |
Correct |
157 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 |
Incorrect |
1 ms |
288 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |