#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//never guess
//never debug without reviewing code
//never try adding ones or substracting them
//only step by step debug when necessay
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector<vi> res(n,vi(n));
int leader[n]; for(int i = 0; i<n; i++) leader[i] = i;
bool done[n]; memset(done,0,sizeof done);
for(int i = 0; i<n; i++){
if(done[i])continue;
done[i] = true;
set<int> zeros, ones, twos;
for(int j = 0; j<n; j++){
if(p[i][j]==0) zeros.insert(j);
else if(p[i][j]==1){
ones.insert(j);
done[j] = true;
}
else twos.insert(j);
}
for(int x : ones){
for(int j = 0; j<n; j++)
if((p[x][j]==0&&!zeros.count(j))||(p[x][j]==1&&!ones.count(j))||(p[x][j]==2&&!twos.count(j))) return 0;
}
vi comp(ones.begin(),ones.end());
for(int j = 0; j<comp.size()-1; j++){
int a = comp[j], b = comp[j+1];
res[a][b] = res[b][a] = 1;
leader[b] = i;
}
}
memset(done,0,sizeof done);
for(int ii = 0; ii<n; ii++){
int i = leader[ii];
if(done[i]) continue;
done[i] = true;
set<int> t = {i};
for(int k = 0; k<n; k++){
int j = leader[k];
if(p[i][j]==2){ t.insert(j); done[j] = true;}
}
if(t.size()==2) return 0;
if(t.size()<=1) continue;
for(int x : t){
for(int k = 0; k<n; k++){
int j = leader[k];
if((p[x][j]==2&&!t.count(j))||(p[x][j]==0&&t.count(j))) return 0;
}
}
vi comp(t.begin(),t.end());
for(int j = 0; j<comp.size()-1; j++){
int a = comp[j], b = comp[j+1];
res[a][b] = res[b][a] = 1;
}
int a = comp[0], b = comp[comp.size()-1];
res[a][b] = res[b][a] = 1;
}
build(res);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:50:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int j = 0; j<comp.size()-1; j++){
| ~^~~~~~~~~~~~~~
supertrees.cpp:75:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int j = 0; j<comp.size()-1; j++){
| ~^~~~~~~~~~~~~~
# |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1116 KB |
Output is correct |
7 |
Correct |
121 ms |
22136 KB |
Output is correct |
# |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1116 KB |
Output is correct |
7 |
Correct |
121 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1116 KB |
Output is correct |
13 |
Correct |
169 ms |
22036 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
54 ms |
12088 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
33 ms |
5724 KB |
Output is correct |
21 |
Correct |
124 ms |
22096 KB |
Output is correct |
22 |
Correct |
143 ms |
22100 KB |
Output is correct |
23 |
Correct |
127 ms |
22100 KB |
Output is correct |
24 |
Correct |
173 ms |
22040 KB |
Output is correct |
25 |
Correct |
59 ms |
12112 KB |
Output is correct |
26 |
Correct |
50 ms |
12116 KB |
Output is correct |
27 |
Correct |
131 ms |
22044 KB |
Output is correct |
28 |
Correct |
169 ms |
22020 KB |
Output is correct |
# |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
1188 KB |
Output is correct |
9 |
Correct |
182 ms |
22036 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
7 ms |
1104 KB |
Output is correct |
13 |
Correct |
183 ms |
22032 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
860 KB |
Output is correct |
17 |
Correct |
151 ms |
12300 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
50 ms |
5760 KB |
Output is correct |
22 |
Correct |
195 ms |
23940 KB |
Output is correct |
23 |
Correct |
192 ms |
24148 KB |
Output is correct |
24 |
Correct |
202 ms |
24144 KB |
Output is correct |
25 |
Correct |
109 ms |
14216 KB |
Output is correct |
26 |
Correct |
125 ms |
14216 KB |
Output is correct |
27 |
Correct |
176 ms |
24144 KB |
Output is correct |
28 |
Correct |
213 ms |
23928 KB |
Output is correct |
29 |
Correct |
114 ms |
14160 KB |
Output is correct |
# |
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 |
34 ms |
5872 KB |
Output is correct |
5 |
Correct |
133 ms |
22096 KB |
Output is correct |
6 |
Correct |
141 ms |
22012 KB |
Output is correct |
7 |
Correct |
134 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
44 ms |
5736 KB |
Output is correct |
10 |
Correct |
209 ms |
24100 KB |
Output is correct |
11 |
Correct |
193 ms |
23912 KB |
Output is correct |
12 |
Correct |
194 ms |
23940 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
432 KB |
Output is correct |
16 |
Correct |
46 ms |
6308 KB |
Output is correct |
17 |
Correct |
203 ms |
24144 KB |
Output is correct |
18 |
Correct |
163 ms |
24148 KB |
Output is correct |
19 |
Correct |
206 ms |
24144 KB |
Output is correct |
20 |
Correct |
170 ms |
24148 KB |
Output is correct |
# |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1116 KB |
Output is correct |
7 |
Correct |
121 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1116 KB |
Output is correct |
13 |
Correct |
169 ms |
22036 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
54 ms |
12088 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
33 ms |
5724 KB |
Output is correct |
21 |
Correct |
124 ms |
22096 KB |
Output is correct |
22 |
Correct |
143 ms |
22100 KB |
Output is correct |
23 |
Correct |
127 ms |
22100 KB |
Output is correct |
24 |
Correct |
173 ms |
22040 KB |
Output is correct |
25 |
Correct |
59 ms |
12112 KB |
Output is correct |
26 |
Correct |
50 ms |
12116 KB |
Output is correct |
27 |
Correct |
131 ms |
22044 KB |
Output is correct |
28 |
Correct |
169 ms |
22020 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
7 ms |
1188 KB |
Output is correct |
37 |
Correct |
182 ms |
22036 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
600 KB |
Output is correct |
40 |
Correct |
7 ms |
1104 KB |
Output is correct |
41 |
Correct |
183 ms |
22032 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
6 ms |
860 KB |
Output is correct |
45 |
Correct |
151 ms |
12300 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
50 ms |
5760 KB |
Output is correct |
50 |
Correct |
195 ms |
23940 KB |
Output is correct |
51 |
Correct |
192 ms |
24148 KB |
Output is correct |
52 |
Correct |
202 ms |
24144 KB |
Output is correct |
53 |
Correct |
109 ms |
14216 KB |
Output is correct |
54 |
Correct |
125 ms |
14216 KB |
Output is correct |
55 |
Correct |
176 ms |
24144 KB |
Output is correct |
56 |
Correct |
213 ms |
23928 KB |
Output is correct |
57 |
Correct |
114 ms |
14160 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
856 KB |
Output is correct |
61 |
Correct |
54 ms |
14216 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
43 ms |
6228 KB |
Output is correct |
66 |
Correct |
66 ms |
14160 KB |
Output is correct |
67 |
Correct |
52 ms |
14160 KB |
Output is correct |
68 |
Correct |
61 ms |
14220 KB |
Output is correct |
69 |
Correct |
114 ms |
14068 KB |
Output is correct |
# |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1116 KB |
Output is correct |
7 |
Correct |
121 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1116 KB |
Output is correct |
13 |
Correct |
169 ms |
22036 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
54 ms |
12088 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
33 ms |
5724 KB |
Output is correct |
21 |
Correct |
124 ms |
22096 KB |
Output is correct |
22 |
Correct |
143 ms |
22100 KB |
Output is correct |
23 |
Correct |
127 ms |
22100 KB |
Output is correct |
24 |
Correct |
173 ms |
22040 KB |
Output is correct |
25 |
Correct |
59 ms |
12112 KB |
Output is correct |
26 |
Correct |
50 ms |
12116 KB |
Output is correct |
27 |
Correct |
131 ms |
22044 KB |
Output is correct |
28 |
Correct |
169 ms |
22020 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
7 ms |
1188 KB |
Output is correct |
37 |
Correct |
182 ms |
22036 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
600 KB |
Output is correct |
40 |
Correct |
7 ms |
1104 KB |
Output is correct |
41 |
Correct |
183 ms |
22032 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
6 ms |
860 KB |
Output is correct |
45 |
Correct |
151 ms |
12300 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
50 ms |
5760 KB |
Output is correct |
50 |
Correct |
195 ms |
23940 KB |
Output is correct |
51 |
Correct |
192 ms |
24148 KB |
Output is correct |
52 |
Correct |
202 ms |
24144 KB |
Output is correct |
53 |
Correct |
109 ms |
14216 KB |
Output is correct |
54 |
Correct |
125 ms |
14216 KB |
Output is correct |
55 |
Correct |
176 ms |
24144 KB |
Output is correct |
56 |
Correct |
213 ms |
23928 KB |
Output is correct |
57 |
Correct |
114 ms |
14160 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
34 ms |
5872 KB |
Output is correct |
62 |
Correct |
133 ms |
22096 KB |
Output is correct |
63 |
Correct |
141 ms |
22012 KB |
Output is correct |
64 |
Correct |
134 ms |
22100 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
44 ms |
5736 KB |
Output is correct |
67 |
Correct |
209 ms |
24100 KB |
Output is correct |
68 |
Correct |
193 ms |
23912 KB |
Output is correct |
69 |
Correct |
194 ms |
23940 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
432 KB |
Output is correct |
73 |
Correct |
46 ms |
6308 KB |
Output is correct |
74 |
Correct |
203 ms |
24144 KB |
Output is correct |
75 |
Correct |
163 ms |
24148 KB |
Output is correct |
76 |
Correct |
206 ms |
24144 KB |
Output is correct |
77 |
Correct |
170 ms |
24148 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
856 KB |
Output is correct |
81 |
Correct |
54 ms |
14216 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
43 ms |
6228 KB |
Output is correct |
86 |
Correct |
66 ms |
14160 KB |
Output is correct |
87 |
Correct |
52 ms |
14160 KB |
Output is correct |
88 |
Correct |
61 ms |
14220 KB |
Output is correct |
89 |
Correct |
114 ms |
14068 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
3 ms |
860 KB |
Output is correct |
93 |
Correct |
51 ms |
14088 KB |
Output is correct |
94 |
Correct |
0 ms |
344 KB |
Output is correct |
95 |
Incorrect |
0 ms |
388 KB |
Answer gives possible 1 while actual possible 0 |
96 |
Halted |
0 ms |
0 KB |
- |