// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,popcnt")
#include <bits/stdc++.h>
#include "supertrees.h"
#define lli long long int
#define ld long double
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end();
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define MP make_pair
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 1e5 + 5;
const int INF = 1e9 + 500;
const int MOD = 1e9 + 7;
struct DSU {
vector<int> p, sz;
int n;
void make_set(int x) {
p[x] = x;
sz[x] = 1;
}
void init(int nn) {
n = nn;
p.assign(n + 3, 0);
sz.assign(n + 3, 0);
for(int i = 0; i < n; i++) {
make_set(i);
}
}
int find_set(int x) {
return (x == p[x]) ? x : p[x] = find_set(p[x]);
}
bool union_set(int x, int y) {
x = find_set(x); y = find_set(y);
if(x == y) return 0;
if(sz[x] < sz[y]) swap(x, y);
sz[x] += sz[y];
p[y] = x;
return 1;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = (int)p.size();
vector<vector<int> > ans(n, vector<int>(n, 0));
DSU ds, ds2;
ds.init(n);
// check zero
bool f = 1;
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(p[i][j]) {
ds.union_set(i, j);
}
}
}
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(!p[i][j] && ds.find_set(i) == ds.find_set(j)) {
f = 0;
}
}
}
if(!f) return 0;
cerr << "zort" << endl;
ds.init(n);
ds2.init(n);
// connect 1 and 2 separately
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(p[i][j] == 1) {
ds.union_set(i, j);
}
else if(p[i][j] == 2) {
ds2.union_set(i, j);
}
}
}
vector<vector<int> > cmp(n, vector<int>());
for(int i = 0; i < n; i++) {
cmp[ds.find_set(i)].pb(i);
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < (int)cmp[i].size() - 1; j++) {
// assert(j + 1 <= (int)cmp[i].size() - 1);
// assert(ans[cmp[i][j]].size() == 4);
// assert(ans[cmp[i][j + 1]].size() == 4);
ans[cmp[i][j]][cmp[i][j + 1]] = 1;
ans[cmp[i][j + 1]][cmp[i][j]] = 1;
}
}
cmp.assign(n, vector<int>());
for(int i = 0; i < n; i++) {
cmp[ds2.find_set(i)].pb(i);
}
for(int i = 0; i < n; i++) {
if(cmp[i].size() == 2) {
f = 0;
}
if(cmp[i].size() < 2) continue;
for(int j = 0; j < cmp[i].size() - 1; j++) {
ans[cmp[i][j]][cmp[i][j + 1]] = 1;
ans[cmp[i][j + 1]][cmp[i][j]] = 1;
}
ans[cmp[i][0]][cmp[i][cmp[i].size() - 1]] = 1;
ans[cmp[i][cmp[i].size() - 1]][cmp[i][0]] = 1;
}
if(!f) return 0;
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:113:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int j = 0; j < cmp[i].size() - 1; j++) {
| ~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1368 KB |
Output is correct |
7 |
Correct |
174 ms |
24052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1368 KB |
Output is correct |
7 |
Correct |
174 ms |
24052 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1368 KB |
Output is correct |
13 |
Correct |
170 ms |
24264 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
89 ms |
14088 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
57 ms |
6236 KB |
Output is correct |
21 |
Correct |
182 ms |
24148 KB |
Output is correct |
22 |
Correct |
175 ms |
24192 KB |
Output is correct |
23 |
Correct |
179 ms |
24080 KB |
Output is correct |
24 |
Correct |
171 ms |
24144 KB |
Output is correct |
25 |
Correct |
89 ms |
14068 KB |
Output is correct |
26 |
Correct |
79 ms |
13996 KB |
Output is correct |
27 |
Correct |
186 ms |
24060 KB |
Output is correct |
28 |
Correct |
167 ms |
24148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
7 ms |
1372 KB |
Output is correct |
9 |
Correct |
200 ms |
24184 KB |
Output is correct |
10 |
Correct |
1 ms |
428 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
9 ms |
1412 KB |
Output is correct |
13 |
Correct |
173 ms |
24200 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
90 ms |
14068 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
43 ms |
6288 KB |
Output is correct |
22 |
Correct |
175 ms |
24152 KB |
Output is correct |
23 |
Correct |
173 ms |
24148 KB |
Output is correct |
24 |
Correct |
184 ms |
24052 KB |
Output is correct |
25 |
Correct |
86 ms |
14204 KB |
Output is correct |
26 |
Correct |
86 ms |
14092 KB |
Output is correct |
27 |
Correct |
170 ms |
24072 KB |
Output is correct |
28 |
Correct |
185 ms |
24148 KB |
Output is correct |
29 |
Correct |
79 ms |
14164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
43 ms |
6428 KB |
Output is correct |
5 |
Correct |
171 ms |
24144 KB |
Output is correct |
6 |
Correct |
172 ms |
24432 KB |
Output is correct |
7 |
Correct |
178 ms |
24164 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
42 ms |
6260 KB |
Output is correct |
10 |
Correct |
177 ms |
24144 KB |
Output is correct |
11 |
Correct |
167 ms |
24144 KB |
Output is correct |
12 |
Correct |
181 ms |
24148 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1368 KB |
Output is correct |
7 |
Correct |
174 ms |
24052 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1368 KB |
Output is correct |
13 |
Correct |
170 ms |
24264 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
89 ms |
14088 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
57 ms |
6236 KB |
Output is correct |
21 |
Correct |
182 ms |
24148 KB |
Output is correct |
22 |
Correct |
175 ms |
24192 KB |
Output is correct |
23 |
Correct |
179 ms |
24080 KB |
Output is correct |
24 |
Correct |
171 ms |
24144 KB |
Output is correct |
25 |
Correct |
89 ms |
14068 KB |
Output is correct |
26 |
Correct |
79 ms |
13996 KB |
Output is correct |
27 |
Correct |
186 ms |
24060 KB |
Output is correct |
28 |
Correct |
167 ms |
24148 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
352 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
436 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
200 ms |
24184 KB |
Output is correct |
38 |
Correct |
1 ms |
428 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
9 ms |
1412 KB |
Output is correct |
41 |
Correct |
173 ms |
24200 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
4 ms |
860 KB |
Output is correct |
45 |
Correct |
90 ms |
14068 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
43 ms |
6288 KB |
Output is correct |
50 |
Correct |
175 ms |
24152 KB |
Output is correct |
51 |
Correct |
173 ms |
24148 KB |
Output is correct |
52 |
Correct |
184 ms |
24052 KB |
Output is correct |
53 |
Correct |
86 ms |
14204 KB |
Output is correct |
54 |
Correct |
86 ms |
14092 KB |
Output is correct |
55 |
Correct |
170 ms |
24072 KB |
Output is correct |
56 |
Correct |
185 ms |
24148 KB |
Output is correct |
57 |
Correct |
79 ms |
14164 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
4 ms |
860 KB |
Output is correct |
61 |
Correct |
89 ms |
14200 KB |
Output is correct |
62 |
Correct |
1 ms |
344 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Incorrect |
42 ms |
6280 KB |
Too many ways to get from 1 to 269, should be 1 found no less than 2 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1368 KB |
Output is correct |
7 |
Correct |
174 ms |
24052 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1368 KB |
Output is correct |
13 |
Correct |
170 ms |
24264 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
89 ms |
14088 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
57 ms |
6236 KB |
Output is correct |
21 |
Correct |
182 ms |
24148 KB |
Output is correct |
22 |
Correct |
175 ms |
24192 KB |
Output is correct |
23 |
Correct |
179 ms |
24080 KB |
Output is correct |
24 |
Correct |
171 ms |
24144 KB |
Output is correct |
25 |
Correct |
89 ms |
14068 KB |
Output is correct |
26 |
Correct |
79 ms |
13996 KB |
Output is correct |
27 |
Correct |
186 ms |
24060 KB |
Output is correct |
28 |
Correct |
167 ms |
24148 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
352 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
436 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
200 ms |
24184 KB |
Output is correct |
38 |
Correct |
1 ms |
428 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
9 ms |
1412 KB |
Output is correct |
41 |
Correct |
173 ms |
24200 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
4 ms |
860 KB |
Output is correct |
45 |
Correct |
90 ms |
14068 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
43 ms |
6288 KB |
Output is correct |
50 |
Correct |
175 ms |
24152 KB |
Output is correct |
51 |
Correct |
173 ms |
24148 KB |
Output is correct |
52 |
Correct |
184 ms |
24052 KB |
Output is correct |
53 |
Correct |
86 ms |
14204 KB |
Output is correct |
54 |
Correct |
86 ms |
14092 KB |
Output is correct |
55 |
Correct |
170 ms |
24072 KB |
Output is correct |
56 |
Correct |
185 ms |
24148 KB |
Output is correct |
57 |
Correct |
79 ms |
14164 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
43 ms |
6428 KB |
Output is correct |
62 |
Correct |
171 ms |
24144 KB |
Output is correct |
63 |
Correct |
172 ms |
24432 KB |
Output is correct |
64 |
Correct |
178 ms |
24164 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
42 ms |
6260 KB |
Output is correct |
67 |
Correct |
177 ms |
24144 KB |
Output is correct |
68 |
Correct |
167 ms |
24144 KB |
Output is correct |
69 |
Correct |
181 ms |
24148 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Incorrect |
1 ms |
348 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
73 |
Halted |
0 ms |
0 KB |
- |