#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
const int md = 1e9+7;
const ll inf = 1e18;
const int maxn = 1e3+5;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
vector<int> par;
vector<int> subpar;
vector< vector<int> > res;
vector<int> bucks[maxn];
vector<int> subbucks[maxn];
void init(vector<int> &p)
{
for(int i = 0; i< (int) p.size(); i++) p[i] = i;
}
int findset(vector<int> &p, int x)
{
if(p[x] == x) return x;
return p[x] = findset(p, p[x]);
}
void unionset(vector<int> &p, int x, int y)
{
int a = findset(p, x);
int b = findset(p, y);
if(a == b) return;
p[a] = b;
}
void addedge(int u, int v)
{
res[u][v] = res[v][u] = 1;
}
int construct(std::vector<std::vector<int>> p)
{
int n = p.size();
par = vector<int>(n, 0);
subpar = vector<int>(n, 0);
res.assign(n, vector<int>(n, 0));
init(par); init(subpar);
bool good = true;
for(int i = 0; i< n; i++)
{
for(int j = i+1; j< n; j++)
{
if(p[i][j] > 0)
{
if(p[i][j] == 3) return 0;
unionset(par, i, j);
}
}
}
for(int i = 0; i< n; i++)
{
for(int j = i+1; j< n; j++)
{
if(p[i][j] == 0)
{
if(findset(par, i) == findset(par, j))
{
return 0;
}
}
}
}
for(int i = 0; i< n; i++)
{
for(int j = i+1; j< n; j++)
{
if(p[i][j] == 1)
{
unionset(subpar, i, j);
}
}
}
for(int i = 0; i< n; i++)
{
for(int j = i+1; j< n; j++)
{
if(p[i][j] >= 2)
{
if(findset(subpar, i) == findset(subpar, j))
{
return 0;
}
}
}
}
for(int i = 0; i< n; i++)
{
if(findset(subpar, i) != i)
{
addedge(findset(subpar, i), i);
}
else bucks[findset(par, i)].pb(i);
subbucks[findset(subpar, i)].pb(i);
}
for(int i = 0; i< n; i++)
{
if((int) bucks[i].size() <= 1) continue;
if((int) bucks[i].size() == 2) return 0;
int val = -1;
for(int j = 0; j< (int) bucks[i].size(); j++)
{
for(int k = j+1; k< (int) bucks[i].size(); k++)
{
int u = bucks[i][j], v = bucks[i][k];
for(int su : subbucks[u])
{
for(int sv : subbucks[v])
{
if(val == -1) val = p[su][sv];
else if(val != p[su][sv]) return 0;
}
}
}
}
for(int j = 0; j+1< (int) bucks[i].size(); j++)
{
addedge(bucks[i][j], bucks[i][j+1]);
}
addedge(bucks[i][0], bucks[i].back());
if(val == 3 && bucks[i].size() == 3) return 0;
if(val == 3) addedge(bucks[i][0], bucks[i][2]);
}
build(res);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:69:7: warning: unused variable 'good' [-Wunused-variable]
69 | bool good = true;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
236 ms |
22328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
236 ms |
22328 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1208 KB |
Output is correct |
13 |
Correct |
237 ms |
22312 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
107 ms |
12088 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
58 ms |
5700 KB |
Output is correct |
21 |
Correct |
236 ms |
22084 KB |
Output is correct |
22 |
Correct |
233 ms |
22088 KB |
Output is correct |
23 |
Correct |
247 ms |
22084 KB |
Output is correct |
24 |
Correct |
232 ms |
22148 KB |
Output is correct |
25 |
Correct |
96 ms |
12076 KB |
Output is correct |
26 |
Correct |
96 ms |
12084 KB |
Output is correct |
27 |
Correct |
250 ms |
22000 KB |
Output is correct |
28 |
Correct |
230 ms |
22124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
13 ms |
1228 KB |
Output is correct |
9 |
Correct |
224 ms |
22072 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1172 KB |
Output is correct |
13 |
Correct |
233 ms |
22068 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
104 ms |
12084 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
58 ms |
5764 KB |
Output is correct |
22 |
Correct |
235 ms |
22136 KB |
Output is correct |
23 |
Correct |
237 ms |
22108 KB |
Output is correct |
24 |
Correct |
250 ms |
22060 KB |
Output is correct |
25 |
Correct |
95 ms |
12204 KB |
Output is correct |
26 |
Correct |
97 ms |
12092 KB |
Output is correct |
27 |
Correct |
227 ms |
22068 KB |
Output is correct |
28 |
Correct |
243 ms |
22084 KB |
Output is correct |
29 |
Correct |
97 ms |
12232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
60 ms |
5756 KB |
Output is correct |
5 |
Correct |
231 ms |
22084 KB |
Output is correct |
6 |
Correct |
237 ms |
22196 KB |
Output is correct |
7 |
Correct |
254 ms |
22084 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
57 ms |
5804 KB |
Output is correct |
10 |
Correct |
231 ms |
22192 KB |
Output is correct |
11 |
Correct |
227 ms |
22084 KB |
Output is correct |
12 |
Correct |
242 ms |
22064 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
58 ms |
5804 KB |
Output is correct |
17 |
Correct |
237 ms |
22056 KB |
Output is correct |
18 |
Correct |
243 ms |
22060 KB |
Output is correct |
19 |
Correct |
233 ms |
22052 KB |
Output is correct |
20 |
Correct |
232 ms |
22328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
236 ms |
22328 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1208 KB |
Output is correct |
13 |
Correct |
237 ms |
22312 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
107 ms |
12088 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
58 ms |
5700 KB |
Output is correct |
21 |
Correct |
236 ms |
22084 KB |
Output is correct |
22 |
Correct |
233 ms |
22088 KB |
Output is correct |
23 |
Correct |
247 ms |
22084 KB |
Output is correct |
24 |
Correct |
232 ms |
22148 KB |
Output is correct |
25 |
Correct |
96 ms |
12076 KB |
Output is correct |
26 |
Correct |
96 ms |
12084 KB |
Output is correct |
27 |
Correct |
250 ms |
22000 KB |
Output is correct |
28 |
Correct |
230 ms |
22124 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
13 ms |
1228 KB |
Output is correct |
37 |
Correct |
224 ms |
22072 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
10 ms |
1172 KB |
Output is correct |
41 |
Correct |
233 ms |
22068 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
104 ms |
12084 KB |
Output is correct |
46 |
Correct |
0 ms |
332 KB |
Output is correct |
47 |
Correct |
0 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
58 ms |
5764 KB |
Output is correct |
50 |
Correct |
235 ms |
22136 KB |
Output is correct |
51 |
Correct |
237 ms |
22108 KB |
Output is correct |
52 |
Correct |
250 ms |
22060 KB |
Output is correct |
53 |
Correct |
95 ms |
12204 KB |
Output is correct |
54 |
Correct |
97 ms |
12092 KB |
Output is correct |
55 |
Correct |
227 ms |
22068 KB |
Output is correct |
56 |
Correct |
243 ms |
22084 KB |
Output is correct |
57 |
Correct |
97 ms |
12232 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
5 ms |
716 KB |
Output is correct |
61 |
Correct |
104 ms |
12080 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
0 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
62 ms |
5748 KB |
Output is correct |
66 |
Correct |
96 ms |
12072 KB |
Output is correct |
67 |
Correct |
96 ms |
12088 KB |
Output is correct |
68 |
Correct |
97 ms |
12088 KB |
Output is correct |
69 |
Correct |
97 ms |
12220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
236 ms |
22328 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1208 KB |
Output is correct |
13 |
Correct |
237 ms |
22312 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
107 ms |
12088 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
58 ms |
5700 KB |
Output is correct |
21 |
Correct |
236 ms |
22084 KB |
Output is correct |
22 |
Correct |
233 ms |
22088 KB |
Output is correct |
23 |
Correct |
247 ms |
22084 KB |
Output is correct |
24 |
Correct |
232 ms |
22148 KB |
Output is correct |
25 |
Correct |
96 ms |
12076 KB |
Output is correct |
26 |
Correct |
96 ms |
12084 KB |
Output is correct |
27 |
Correct |
250 ms |
22000 KB |
Output is correct |
28 |
Correct |
230 ms |
22124 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
13 ms |
1228 KB |
Output is correct |
37 |
Correct |
224 ms |
22072 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
10 ms |
1172 KB |
Output is correct |
41 |
Correct |
233 ms |
22068 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
104 ms |
12084 KB |
Output is correct |
46 |
Correct |
0 ms |
332 KB |
Output is correct |
47 |
Correct |
0 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
58 ms |
5764 KB |
Output is correct |
50 |
Correct |
235 ms |
22136 KB |
Output is correct |
51 |
Correct |
237 ms |
22108 KB |
Output is correct |
52 |
Correct |
250 ms |
22060 KB |
Output is correct |
53 |
Correct |
95 ms |
12204 KB |
Output is correct |
54 |
Correct |
97 ms |
12092 KB |
Output is correct |
55 |
Correct |
227 ms |
22068 KB |
Output is correct |
56 |
Correct |
243 ms |
22084 KB |
Output is correct |
57 |
Correct |
97 ms |
12232 KB |
Output is correct |
58 |
Correct |
0 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
0 ms |
332 KB |
Output is correct |
61 |
Correct |
60 ms |
5756 KB |
Output is correct |
62 |
Correct |
231 ms |
22084 KB |
Output is correct |
63 |
Correct |
237 ms |
22196 KB |
Output is correct |
64 |
Correct |
254 ms |
22084 KB |
Output is correct |
65 |
Correct |
0 ms |
332 KB |
Output is correct |
66 |
Correct |
57 ms |
5804 KB |
Output is correct |
67 |
Correct |
231 ms |
22192 KB |
Output is correct |
68 |
Correct |
227 ms |
22084 KB |
Output is correct |
69 |
Correct |
242 ms |
22064 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |
71 |
Correct |
0 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
58 ms |
5804 KB |
Output is correct |
74 |
Correct |
237 ms |
22056 KB |
Output is correct |
75 |
Correct |
243 ms |
22060 KB |
Output is correct |
76 |
Correct |
233 ms |
22052 KB |
Output is correct |
77 |
Correct |
232 ms |
22328 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
0 ms |
332 KB |
Output is correct |
80 |
Correct |
5 ms |
716 KB |
Output is correct |
81 |
Correct |
104 ms |
12080 KB |
Output is correct |
82 |
Correct |
1 ms |
332 KB |
Output is correct |
83 |
Correct |
0 ms |
332 KB |
Output is correct |
84 |
Correct |
1 ms |
332 KB |
Output is correct |
85 |
Correct |
62 ms |
5748 KB |
Output is correct |
86 |
Correct |
96 ms |
12072 KB |
Output is correct |
87 |
Correct |
96 ms |
12088 KB |
Output is correct |
88 |
Correct |
97 ms |
12088 KB |
Output is correct |
89 |
Correct |
97 ms |
12220 KB |
Output is correct |
90 |
Correct |
1 ms |
332 KB |
Output is correct |
91 |
Correct |
0 ms |
332 KB |
Output is correct |
92 |
Correct |
4 ms |
716 KB |
Output is correct |
93 |
Correct |
98 ms |
12084 KB |
Output is correct |
94 |
Correct |
0 ms |
332 KB |
Output is correct |
95 |
Correct |
1 ms |
332 KB |
Output is correct |
96 |
Correct |
0 ms |
332 KB |
Output is correct |
97 |
Correct |
23 ms |
3244 KB |
Output is correct |
98 |
Correct |
95 ms |
12084 KB |
Output is correct |
99 |
Correct |
99 ms |
12084 KB |
Output is correct |
100 |
Correct |
98 ms |
12084 KB |
Output is correct |
101 |
Correct |
97 ms |
12084 KB |
Output is correct |
102 |
Correct |
94 ms |
12076 KB |
Output is correct |
103 |
Correct |
95 ms |
14112 KB |
Output is correct |
104 |
Correct |
94 ms |
14148 KB |
Output is correct |
105 |
Correct |
109 ms |
14252 KB |
Output is correct |