#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "supertrees.h"
VVI comps(VVI s, bool t0, bool t1, bool t2) {
/*transformations*/
int n = s.size();
rep(i, n) rep(j, n) {
if (s[i][j] == 0) s[i][j] = t0;
else if (s[i][j] == 1) s[i][j] = t1;
else if (s[i][j] == 2) s[i][j] = t2;
}
sort(all(s));
VVI ret;
for (int i = 0; i < n; i++) {
if (i == 0 || s[i] != s[i-1]) {
if (i) rep(j, n) {
if (s[i][j] && s[i-1][j]) {
return VVI();
}
}
ret.pb(VI());
rep(j, n) if (s[i][j]) ret.back().pb(j);
}
}
return ret;
}
int construct(VVI p) {
int n = p.size();
VVI comp = comps(p, 0, 1, 1);
if (comp.size() == 0) return 0;
VVI ans(n, VI(n));
/*for (VI vec : comp) {*/
/* replr(i, 1, vec.size()-1) {*/
/* ans[vec[0]][vec[i]] = true;*/
/* ans[vec[i]][vec[0]] = true;*/
/* }*/
/*}*/
VVVI a;
for (VI vec : comp) {
int s = vec.size();
a.pb(VVI(s, VI(s)));
rep(i, s) {
rep(j, s) {
int x = vec[i];
int y = vec[j];
a.back()[i][j] = p[x][y];
}
}
}
VPI edges;
rep(c, comp.size()) {
int n = comp[c].size();
VVI p = a[c];
VVI trees = comps(p, 0, 1, 0);
if (trees.size() == 0) return 0;
for (VI& v : trees) for (int& x : v) x = comp[c][x];
/*cout << "COMPONENT ";*/
/*for (int x : comp[c]) cout << x << " "; cout << endl;*/
/*rep(i, n) {*/
/* rep(j, n) cout << p[i][j] << " ";*/
/* cout << endl;*/
/*}*/
/*for (VI v : trees) {*/
/* cout << " TREE ";*/
/* for (int x : v) cout << x << " ";*/
/* cout << endl;*/
/*}*/
VI roots;
for (VI v : trees) {
int r = v[0];
roots.pb(r);
replr(i, 1, v.size()-1) {
edges.pb({r, v[i]});
}
}
int r = roots.size();
if (r == 1) continue;
rep(i, r) {
edges.pb({roots[i], roots[(i+1)%r]});
}
}
for (auto[u, v] : edges) {
ans[u][v] = ans[v][u] = 1;
/*cout << u << " " << v << endl;*/
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(VVI)':
supertrees.cpp:84:13: warning: unused variable 'n' [-Wunused-variable]
84 | int n = comp[c].size();
| ^
supertrees.cpp:118:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
118 | for (auto[u, v] : edges) {
| ^
# |
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 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1560 KB |
Output is correct |
7 |
Correct |
118 ms |
27244 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1560 KB |
Output is correct |
7 |
Correct |
118 ms |
27244 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
432 KB |
Output is correct |
12 |
Correct |
4 ms |
1184 KB |
Output is correct |
13 |
Correct |
97 ms |
23376 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
49 ms |
13484 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
24 ms |
6364 KB |
Output is correct |
21 |
Correct |
100 ms |
23840 KB |
Output is correct |
22 |
Correct |
99 ms |
23376 KB |
Output is correct |
23 |
Correct |
107 ms |
25240 KB |
Output is correct |
24 |
Correct |
98 ms |
23376 KB |
Output is correct |
25 |
Correct |
45 ms |
13392 KB |
Output is correct |
26 |
Correct |
42 ms |
13320 KB |
Output is correct |
27 |
Correct |
108 ms |
25236 KB |
Output is correct |
28 |
Correct |
97 ms |
23376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
24 ms |
6412 KB |
Output is correct |
5 |
Correct |
104 ms |
24408 KB |
Output is correct |
6 |
Correct |
95 ms |
24004 KB |
Output is correct |
7 |
Correct |
107 ms |
26008 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
24 ms |
6480 KB |
Output is correct |
10 |
Correct |
98 ms |
24460 KB |
Output is correct |
11 |
Correct |
97 ms |
23936 KB |
Output is correct |
12 |
Correct |
106 ms |
25940 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
24 ms |
6344 KB |
Output is correct |
17 |
Correct |
99 ms |
24404 KB |
Output is correct |
18 |
Correct |
98 ms |
24404 KB |
Output is correct |
19 |
Correct |
97 ms |
24144 KB |
Output is correct |
20 |
Correct |
99 ms |
24144 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1560 KB |
Output is correct |
7 |
Correct |
118 ms |
27244 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
432 KB |
Output is correct |
12 |
Correct |
4 ms |
1184 KB |
Output is correct |
13 |
Correct |
97 ms |
23376 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
49 ms |
13484 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
24 ms |
6364 KB |
Output is correct |
21 |
Correct |
100 ms |
23840 KB |
Output is correct |
22 |
Correct |
99 ms |
23376 KB |
Output is correct |
23 |
Correct |
107 ms |
25240 KB |
Output is correct |
24 |
Correct |
98 ms |
23376 KB |
Output is correct |
25 |
Correct |
45 ms |
13392 KB |
Output is correct |
26 |
Correct |
42 ms |
13320 KB |
Output is correct |
27 |
Correct |
108 ms |
25236 KB |
Output is correct |
28 |
Correct |
97 ms |
23376 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 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 |
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 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1560 KB |
Output is correct |
7 |
Correct |
118 ms |
27244 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
432 KB |
Output is correct |
12 |
Correct |
4 ms |
1184 KB |
Output is correct |
13 |
Correct |
97 ms |
23376 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
49 ms |
13484 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
24 ms |
6364 KB |
Output is correct |
21 |
Correct |
100 ms |
23840 KB |
Output is correct |
22 |
Correct |
99 ms |
23376 KB |
Output is correct |
23 |
Correct |
107 ms |
25240 KB |
Output is correct |
24 |
Correct |
98 ms |
23376 KB |
Output is correct |
25 |
Correct |
45 ms |
13392 KB |
Output is correct |
26 |
Correct |
42 ms |
13320 KB |
Output is correct |
27 |
Correct |
108 ms |
25236 KB |
Output is correct |
28 |
Correct |
97 ms |
23376 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |