#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#ifdef dremix
#define p(x) cerr<<#x<<" = "<<x<<endl;
#define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
#define pv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<x<<", ";cerr<<"}"<<endl;
#else
#define p(x) {}
#define p2(x,y) {}
#define pv(x) {}
#endif
const ll INF = 2e18+5;
const int MOD = 1e9+7;
const int N = 1005;
vector<vector<int> > ans;
int v[N];
vector<vector<vector<int> > > a(N,vector<vector<int> >(3,vector<int>()));
int nn;
bool flag = true;
vector<int> par(N),siz(N,1);
vector<vector<int> > g(N);
vector<int> s(N),e(N);
int find(int x){
return (par[x] == x) ? x : par[x] = find(par[x]);
}
bool go = false;
bool join(int x, int y){
x = find(x);
y = find(y);
if(x == y)return false;
if(g[y].size() > g[x].size())swap(x,y);
siz[x] += siz[y];
par[y] = x;
for(auto v : g[y])g[x].push_back(v);
g[y].clear();
p2(s[x],e[x])
p2(s[y],e[y])
if(go)
ans[e[x]][s[y]] = ans[s[y]][e[x]] = 1;
e[x] = e[y];
return true;
}
int construct(std::vector<std::vector<int>> p) {
int i,j,n = p.size();
ans.assign(n,vector<int>(n,0));
for(i=0;i<n;i++){
g[i].push_back(i);
for(j=0;j<n;j++){
if(i==j)continue;
if(p[i][j] == 3)return 0;
a[i][p[i][j]].push_back(j);
}
}
iota(all(par),0);
iota(all(s),0);
iota(all(e),0);
for(i=0;i<n;i++){
if(v[i]){
continue;
}
//vector<int> chk;
//chk.push_back(i);
int x = i;
v[i] = true;
for(auto j : a[i][1]){
join(i,j);
p2(i,j)
//chk.push_back(j);
ans[x][j] = ans[j][x] = 1;
x = j;
v[j] = true;
}
s[find(i)] = i;
e[find(i)] = i;
for(int k=0;k<n;k++){
bool ok = true;
int need = p[i][k];
for(auto j : g[find(i)]){
if(j == k)continue;
if(p[j][k] != need){
ok = false;
break;
}
}
if(!ok){
flag = false;
break;
}
}
}
if(!flag)return 0;
fill(all(siz),1);
go = true;
for(i=0;i<n;i++){
for(auto x : a[i][2]){
if(find(i) == find(x))continue;
for(auto v1 : g[find(x)]){
for(auto v2 : g[find(i)])
if(p[v2][v1] != 2){
return 0;
}
}
//ans[i][x] = ans[x][i] = 1;
join(i,x);
p2(i,x)
}
}
for(i=0;i<n;i++){
if(siz[find(i)] == 2)return 0;
}
for(i=0;i<n;i++){
int x = s[find(i)];
int y = e[find(i)];
if(siz[find(i)] == 1)continue;
ans[x][y] = ans[y][x] = 1;
}
if(!flag)return 0;
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
187 ms |
26228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
187 ms |
26228 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1632 KB |
Output is correct |
13 |
Correct |
199 ms |
26268 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1048 KB |
Output is correct |
17 |
Correct |
85 ms |
17068 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
48 ms |
6936 KB |
Output is correct |
21 |
Correct |
188 ms |
26900 KB |
Output is correct |
22 |
Correct |
182 ms |
26268 KB |
Output is correct |
23 |
Correct |
219 ms |
26192 KB |
Output is correct |
24 |
Correct |
186 ms |
26164 KB |
Output is correct |
25 |
Correct |
81 ms |
17100 KB |
Output is correct |
26 |
Correct |
80 ms |
16332 KB |
Output is correct |
27 |
Correct |
211 ms |
28312 KB |
Output is correct |
28 |
Correct |
193 ms |
26260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
8 ms |
1628 KB |
Output is correct |
9 |
Correct |
205 ms |
26592 KB |
Output is correct |
10 |
Correct |
1 ms |
500 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
1616 KB |
Output is correct |
13 |
Correct |
200 ms |
26580 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
448 KB |
Output is correct |
16 |
Correct |
5 ms |
1228 KB |
Output is correct |
17 |
Correct |
106 ms |
19084 KB |
Output is correct |
18 |
Correct |
1 ms |
448 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
49 ms |
7416 KB |
Output is correct |
22 |
Correct |
206 ms |
28856 KB |
Output is correct |
23 |
Correct |
199 ms |
28224 KB |
Output is correct |
24 |
Correct |
248 ms |
30144 KB |
Output is correct |
25 |
Correct |
83 ms |
18248 KB |
Output is correct |
26 |
Correct |
89 ms |
18832 KB |
Output is correct |
27 |
Correct |
202 ms |
28252 KB |
Output is correct |
28 |
Correct |
200 ms |
28320 KB |
Output is correct |
29 |
Correct |
98 ms |
18204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
48 ms |
7360 KB |
Output is correct |
5 |
Correct |
199 ms |
27348 KB |
Output is correct |
6 |
Correct |
191 ms |
26560 KB |
Output is correct |
7 |
Correct |
229 ms |
26672 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
55 ms |
7328 KB |
Output is correct |
10 |
Correct |
194 ms |
27216 KB |
Output is correct |
11 |
Correct |
207 ms |
26688 KB |
Output is correct |
12 |
Correct |
210 ms |
28712 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
48 ms |
7276 KB |
Output is correct |
17 |
Correct |
194 ms |
27400 KB |
Output is correct |
18 |
Correct |
193 ms |
27336 KB |
Output is correct |
19 |
Correct |
222 ms |
26988 KB |
Output is correct |
20 |
Correct |
194 ms |
26700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
187 ms |
26228 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1632 KB |
Output is correct |
13 |
Correct |
199 ms |
26268 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1048 KB |
Output is correct |
17 |
Correct |
85 ms |
17068 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
48 ms |
6936 KB |
Output is correct |
21 |
Correct |
188 ms |
26900 KB |
Output is correct |
22 |
Correct |
182 ms |
26268 KB |
Output is correct |
23 |
Correct |
219 ms |
26192 KB |
Output is correct |
24 |
Correct |
186 ms |
26164 KB |
Output is correct |
25 |
Correct |
81 ms |
17100 KB |
Output is correct |
26 |
Correct |
80 ms |
16332 KB |
Output is correct |
27 |
Correct |
211 ms |
28312 KB |
Output is correct |
28 |
Correct |
193 ms |
26260 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
444 KB |
Output is correct |
36 |
Correct |
8 ms |
1628 KB |
Output is correct |
37 |
Correct |
205 ms |
26592 KB |
Output is correct |
38 |
Correct |
1 ms |
500 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
1616 KB |
Output is correct |
41 |
Correct |
200 ms |
26580 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
448 KB |
Output is correct |
44 |
Correct |
5 ms |
1228 KB |
Output is correct |
45 |
Correct |
106 ms |
19084 KB |
Output is correct |
46 |
Correct |
1 ms |
448 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
49 ms |
7416 KB |
Output is correct |
50 |
Correct |
206 ms |
28856 KB |
Output is correct |
51 |
Correct |
199 ms |
28224 KB |
Output is correct |
52 |
Correct |
248 ms |
30144 KB |
Output is correct |
53 |
Correct |
83 ms |
18248 KB |
Output is correct |
54 |
Correct |
89 ms |
18832 KB |
Output is correct |
55 |
Correct |
202 ms |
28252 KB |
Output is correct |
56 |
Correct |
200 ms |
28320 KB |
Output is correct |
57 |
Correct |
98 ms |
18204 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
444 KB |
Output is correct |
60 |
Correct |
5 ms |
1236 KB |
Output is correct |
61 |
Correct |
94 ms |
20236 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
49 ms |
7440 KB |
Output is correct |
66 |
Correct |
89 ms |
18960 KB |
Output is correct |
67 |
Correct |
87 ms |
18892 KB |
Output is correct |
68 |
Correct |
89 ms |
18452 KB |
Output is correct |
69 |
Correct |
90 ms |
18308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
187 ms |
26228 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1632 KB |
Output is correct |
13 |
Correct |
199 ms |
26268 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1048 KB |
Output is correct |
17 |
Correct |
85 ms |
17068 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
48 ms |
6936 KB |
Output is correct |
21 |
Correct |
188 ms |
26900 KB |
Output is correct |
22 |
Correct |
182 ms |
26268 KB |
Output is correct |
23 |
Correct |
219 ms |
26192 KB |
Output is correct |
24 |
Correct |
186 ms |
26164 KB |
Output is correct |
25 |
Correct |
81 ms |
17100 KB |
Output is correct |
26 |
Correct |
80 ms |
16332 KB |
Output is correct |
27 |
Correct |
211 ms |
28312 KB |
Output is correct |
28 |
Correct |
193 ms |
26260 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
444 KB |
Output is correct |
36 |
Correct |
8 ms |
1628 KB |
Output is correct |
37 |
Correct |
205 ms |
26592 KB |
Output is correct |
38 |
Correct |
1 ms |
500 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
1616 KB |
Output is correct |
41 |
Correct |
200 ms |
26580 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
448 KB |
Output is correct |
44 |
Correct |
5 ms |
1228 KB |
Output is correct |
45 |
Correct |
106 ms |
19084 KB |
Output is correct |
46 |
Correct |
1 ms |
448 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
49 ms |
7416 KB |
Output is correct |
50 |
Correct |
206 ms |
28856 KB |
Output is correct |
51 |
Correct |
199 ms |
28224 KB |
Output is correct |
52 |
Correct |
248 ms |
30144 KB |
Output is correct |
53 |
Correct |
83 ms |
18248 KB |
Output is correct |
54 |
Correct |
89 ms |
18832 KB |
Output is correct |
55 |
Correct |
202 ms |
28252 KB |
Output is correct |
56 |
Correct |
200 ms |
28320 KB |
Output is correct |
57 |
Correct |
98 ms |
18204 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
48 ms |
7360 KB |
Output is correct |
62 |
Correct |
199 ms |
27348 KB |
Output is correct |
63 |
Correct |
191 ms |
26560 KB |
Output is correct |
64 |
Correct |
229 ms |
26672 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
55 ms |
7328 KB |
Output is correct |
67 |
Correct |
194 ms |
27216 KB |
Output is correct |
68 |
Correct |
207 ms |
26688 KB |
Output is correct |
69 |
Correct |
210 ms |
28712 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
48 ms |
7276 KB |
Output is correct |
74 |
Correct |
194 ms |
27400 KB |
Output is correct |
75 |
Correct |
193 ms |
27336 KB |
Output is correct |
76 |
Correct |
222 ms |
26988 KB |
Output is correct |
77 |
Correct |
194 ms |
26700 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
1 ms |
444 KB |
Output is correct |
80 |
Correct |
5 ms |
1236 KB |
Output is correct |
81 |
Correct |
94 ms |
20236 KB |
Output is correct |
82 |
Correct |
1 ms |
340 KB |
Output is correct |
83 |
Correct |
1 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
49 ms |
7440 KB |
Output is correct |
86 |
Correct |
89 ms |
18960 KB |
Output is correct |
87 |
Correct |
87 ms |
18892 KB |
Output is correct |
88 |
Correct |
89 ms |
18452 KB |
Output is correct |
89 |
Correct |
90 ms |
18308 KB |
Output is correct |
90 |
Correct |
1 ms |
444 KB |
Output is correct |
91 |
Correct |
0 ms |
340 KB |
Output is correct |
92 |
Correct |
3 ms |
980 KB |
Output is correct |
93 |
Correct |
71 ms |
14152 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
444 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
19 ms |
3984 KB |
Output is correct |
98 |
Correct |
71 ms |
14480 KB |
Output is correct |
99 |
Correct |
70 ms |
14876 KB |
Output is correct |
100 |
Correct |
68 ms |
14480 KB |
Output is correct |
101 |
Correct |
70 ms |
15508 KB |
Output is correct |
102 |
Correct |
69 ms |
14220 KB |
Output is correct |
103 |
Correct |
73 ms |
14284 KB |
Output is correct |
104 |
Correct |
69 ms |
14220 KB |
Output is correct |
105 |
Correct |
93 ms |
14236 KB |
Output is correct |