#include "supertrees.h"
#include <vector>
#include <numeric>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define pb push_back
int n;
namespace unf {
int par[1010];
void init() {
iota(par, par+n, 0);
}
int r(int x) { return (x==par[x]) ? x : (par[x]=r(par[x])); }
void join(int a, int b) {
a = r(a); b = r(b);
if (a == b) return;
par[a] = b;
}
bool same(int a, int b) { return r(a) == r(b); }
};
using namespace unf;
vector<int> g[1010];
int ans[1010][1010];
vector<int> go[1010];
int work(int gi, auto &p) {
auto &v = g[gi];
if (v.size() == 1u) return 1;
for(int x:v) par[x] = x;
vector<int> v1;
for(int x:v) {
bool ok = 0;
for(int y:v) if (p[x][y] == 1 && x != y) join(x, y), ok = 1;
if (ok) v1.pb(x);
}
for(int x:v1) go[r(x)].pb(x);
for(int x:v1) if (par[x] == x) {
auto &t = go[x];
int gs = t.size();
for(int i=0; i+1<gs; ++i) {
ans[t[i]][t[i+1]] = 1;
ans[t[i+1]][t[i]] = 1;
}
for(int a:t) for(int b:t) if (p[a][b] != 1) return 0;
}
vector<int> cyc;
for(int x:v) if (!par[x] || par[x] == x) cyc.pb(x);
if (cyc.size() <= 2u) return 0;
for(int i=0, s=cyc.size(); i<s-1; ++i) ans[cyc[i]][cyc[i+1]] = ans[cyc[i+1]][cyc[i]] = 1;
ans[cyc[0]][cyc.back()] = ans[cyc.back()][cyc[0]] = 1;
return 1;
}
int construct(vector<vector<int>> p) {
n = p.size();
unf::init();
rep(i, n) rep(j, n) if (p[i][j]) { if (p[i][j] == 3) return 0; join(i, j); }
rep(i, n) rep(j, n) if (same(i, j) != !!p[i][j]) return 0;
rep(i, n) g[r(i)].pb(i);
rep(i, n) if (par[i] == i) if (!work(i, p)) return 0;
rep(i, n) rep(j, n) p[i][j] = ans[i][j];
build(p);
return 1;
}
Compilation message
supertrees.cpp:29:18: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
29 | int work(int gi, auto &p) {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
13 ms |
1152 KB |
Output is correct |
9 |
Correct |
288 ms |
18220 KB |
Output is correct |
10 |
Correct |
1 ms |
360 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
1896 KB |
Output is correct |
13 |
Correct |
291 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
416 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
116 ms |
8312 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
62 ms |
6776 KB |
Output is correct |
22 |
Correct |
255 ms |
22156 KB |
Output is correct |
23 |
Correct |
252 ms |
22136 KB |
Output is correct |
24 |
Correct |
275 ms |
22220 KB |
Output is correct |
25 |
Correct |
105 ms |
8440 KB |
Output is correct |
26 |
Correct |
100 ms |
8184 KB |
Output is correct |
27 |
Correct |
243 ms |
22136 KB |
Output is correct |
28 |
Correct |
270 ms |
22112 KB |
Output is correct |
29 |
Correct |
103 ms |
8440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 0 while actual possible 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |