#include <bits/stdc++.h>
#include "supertrees.h"
/*
author: aykhn
4/28/2023
*/
using namespace std;
typedef long long ll;
#define OPT ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pss pair<long,long>
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout<<endl;
struct DSU
{
vector<int> par;
vector<vector<int>> e;
void init(int n)
{
e.resize(n);
par.resize(n);
for (int i = 0; i < n; i++)
{
e[i].pb(i);
par[i] = i;
}
}
int get(int x)
{
if (par[x] == x) return x;
return par[x] = get(par[x]);
}
bool tog(int x, int y)
{
return get(x) == get(y);
}
void unite(int x, int y)
{
x = get(x);
y = get(y);
if (x == y) return;
if (e[x].size() < e[y].size()) swap(x, y);
for (int a : e[y])
{
e[x].pb(a);
par[a] = x;
}
par[y] = x;
e[y].clear();
}
};
int construct(vector<vector<int>> p)
{
int n = p.size();
vector<vector<int>> b(n, vector<int> (n, 0));
vector<int> used(n, 0);
DSU dsu;
dsu.init(n);
bool flag = false;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (p[i][j]) dsu.unite(i, j);
if (p[i][j] == 2) flag = true;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (!p[i][j] && dsu.tog(i, j)) return 0;
}
}
for (int i = 0; i < n; i++)
{
int x = dsu.get(i);
if (!used[x])
{
if (flag && dsu.e[x].size() == 2) return 0;
for (int j = 0; j + 1 < dsu.e[x].size(); j++)
{
b[dsu.e[x][j]][dsu.e[x][j + 1]] = 1;
b[dsu.e[x][j + 1]][dsu.e[x][j]] = 1;
}
if(flag)
{
b[dsu.e[x][dsu.e[x].size() - 1]][dsu.e[x][0]] = 1;
b[dsu.e[x][0]][dsu.e[x][dsu.e[x].size() - 1]] = 1;
}
}
}
for (int i = 0; i < n; i++) b[i][i] = 0;
build(b);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:114:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | for (int j = 0; j + 1 < dsu.e[x].size(); j++)
| ~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1216 KB |
Output is correct |
7 |
Correct |
185 ms |
24048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1216 KB |
Output is correct |
7 |
Correct |
185 ms |
24048 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
244 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
168 ms |
24064 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
88 ms |
14120 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
6260 KB |
Output is correct |
21 |
Correct |
177 ms |
24048 KB |
Output is correct |
22 |
Correct |
172 ms |
23944 KB |
Output is correct |
23 |
Correct |
193 ms |
23956 KB |
Output is correct |
24 |
Correct |
169 ms |
23964 KB |
Output is correct |
25 |
Correct |
70 ms |
14068 KB |
Output is correct |
26 |
Correct |
66 ms |
14064 KB |
Output is correct |
27 |
Correct |
192 ms |
24052 KB |
Output is correct |
28 |
Correct |
175 ms |
24052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
168 ms |
24052 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 |
1204 KB |
Output is correct |
13 |
Correct |
181 ms |
24052 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
89 ms |
14076 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
49 ms |
6224 KB |
Output is correct |
22 |
Correct |
179 ms |
24064 KB |
Output is correct |
23 |
Correct |
171 ms |
23968 KB |
Output is correct |
24 |
Correct |
192 ms |
24168 KB |
Output is correct |
25 |
Correct |
72 ms |
14200 KB |
Output is correct |
26 |
Correct |
70 ms |
14068 KB |
Output is correct |
27 |
Correct |
172 ms |
24008 KB |
Output is correct |
28 |
Correct |
189 ms |
24048 KB |
Output is correct |
29 |
Correct |
72 ms |
14064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
44 ms |
6260 KB |
Output is correct |
5 |
Correct |
175 ms |
24052 KB |
Output is correct |
6 |
Correct |
170 ms |
24052 KB |
Output is correct |
7 |
Correct |
189 ms |
24052 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
47 ms |
6220 KB |
Output is correct |
10 |
Correct |
197 ms |
24056 KB |
Output is correct |
11 |
Correct |
179 ms |
24060 KB |
Output is correct |
12 |
Correct |
187 ms |
24060 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1216 KB |
Output is correct |
7 |
Correct |
185 ms |
24048 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
244 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
168 ms |
24064 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
88 ms |
14120 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
6260 KB |
Output is correct |
21 |
Correct |
177 ms |
24048 KB |
Output is correct |
22 |
Correct |
172 ms |
23944 KB |
Output is correct |
23 |
Correct |
193 ms |
23956 KB |
Output is correct |
24 |
Correct |
169 ms |
23964 KB |
Output is correct |
25 |
Correct |
70 ms |
14068 KB |
Output is correct |
26 |
Correct |
66 ms |
14064 KB |
Output is correct |
27 |
Correct |
192 ms |
24052 KB |
Output is correct |
28 |
Correct |
175 ms |
24052 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
296 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
300 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
296 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
168 ms |
24052 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
9 ms |
1204 KB |
Output is correct |
41 |
Correct |
181 ms |
24052 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
89 ms |
14076 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
49 ms |
6224 KB |
Output is correct |
50 |
Correct |
179 ms |
24064 KB |
Output is correct |
51 |
Correct |
171 ms |
23968 KB |
Output is correct |
52 |
Correct |
192 ms |
24168 KB |
Output is correct |
53 |
Correct |
72 ms |
14200 KB |
Output is correct |
54 |
Correct |
70 ms |
14068 KB |
Output is correct |
55 |
Correct |
172 ms |
24008 KB |
Output is correct |
56 |
Correct |
189 ms |
24048 KB |
Output is correct |
57 |
Correct |
72 ms |
14064 KB |
Output is correct |
58 |
Correct |
1 ms |
296 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
83 ms |
14120 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 9, should be 1 found no less than 2 |
64 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1216 KB |
Output is correct |
7 |
Correct |
185 ms |
24048 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
244 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
168 ms |
24064 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
88 ms |
14120 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
6260 KB |
Output is correct |
21 |
Correct |
177 ms |
24048 KB |
Output is correct |
22 |
Correct |
172 ms |
23944 KB |
Output is correct |
23 |
Correct |
193 ms |
23956 KB |
Output is correct |
24 |
Correct |
169 ms |
23964 KB |
Output is correct |
25 |
Correct |
70 ms |
14068 KB |
Output is correct |
26 |
Correct |
66 ms |
14064 KB |
Output is correct |
27 |
Correct |
192 ms |
24052 KB |
Output is correct |
28 |
Correct |
175 ms |
24052 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
296 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
300 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
296 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
168 ms |
24052 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
9 ms |
1204 KB |
Output is correct |
41 |
Correct |
181 ms |
24052 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
89 ms |
14076 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
49 ms |
6224 KB |
Output is correct |
50 |
Correct |
179 ms |
24064 KB |
Output is correct |
51 |
Correct |
171 ms |
23968 KB |
Output is correct |
52 |
Correct |
192 ms |
24168 KB |
Output is correct |
53 |
Correct |
72 ms |
14200 KB |
Output is correct |
54 |
Correct |
70 ms |
14068 KB |
Output is correct |
55 |
Correct |
172 ms |
24008 KB |
Output is correct |
56 |
Correct |
189 ms |
24048 KB |
Output is correct |
57 |
Correct |
72 ms |
14064 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
44 ms |
6260 KB |
Output is correct |
62 |
Correct |
175 ms |
24052 KB |
Output is correct |
63 |
Correct |
170 ms |
24052 KB |
Output is correct |
64 |
Correct |
189 ms |
24052 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
47 ms |
6220 KB |
Output is correct |
67 |
Correct |
197 ms |
24056 KB |
Output is correct |
68 |
Correct |
179 ms |
24060 KB |
Output is correct |
69 |
Correct |
187 ms |
24060 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
72 |
Halted |
0 ms |
0 KB |
- |