#include <bits/stdc++.h>
/// #include "supertrees.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pi = pair<ll, pair<ll, ll>>;
using ii = pair<int, int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
void build(vector<vector<int>> B);
int N, par[1001]; vector<int> S[1001];
bool vis[1001];
int findSet(int v) {
if(par[v] == v) return v;
return par[v] = findSet(par[v]);
}
void unionSet(int u, int v) {
u = findSet(u), v = findSet(v);
if(S[u].size() < S[v].size()) swap(u, v);
for(auto e : S[v]) S[u].pb(e);
par[v] = u; S[v].clear();
}
int construct(vector<vector<int>> P) {
N = P.size();
vector<vector<int>> B(N, vector<int>(N, 0));
for(int l = 0; l < N; l++)
par[l] = l, S[l].pb(l);
for(int l = 0; l < N; l++) {
for(int i = l + 1; i < N; i++) {
if(findSet(l) == findSet(i) || P[l][i] == 0)
continue;
unionSet(l, i);
}
}
for(int l = 0; l < N; l++) {
for(int i = l + 1; i < N; i++) {
if(P[l][i] == 0 && findSet(l) == findSet(i))
return 0;
if(P[l][i] >= 1 && findSet(l) != findSet(i))
return 0;
}
}
for(int l = 0; l < N; l++) {
if(S[l].size() <= 1) continue;
bool Uno = 0, Dos = 0, Tres = 0;
for(int i = 0; i < S[l].size(); i++)
for(int j = i + 1; j < S[l].size(); j++)
Uno |= (P[S[l][i]][S[l][j]] == 1),
Dos |= (P[S[l][i]][S[l][j]] == 2),
Tres |= (P[S[l][i]][S[l][j]] == 3);
if(Uno && !Dos && !Tres) {
for(int i = 1; i < S[l].size(); i++)
B[S[l][i]][S[l][i - 1]] = B[S[l][i - 1]][S[l][i]] = 1;
continue;
}
if(Dos && !Uno && !Tres) {
for(int i = 1; i < S[l].size(); i++)
B[S[l][i]][S[l][i - 1]] = B[S[l][i - 1]][S[l][i]] = 1;
int U = S[l][0], V = S[l][S[l].size() - 1];
if(S[l].size() <= 2) return 0;
B[U][V] = B[V][U] = 1;
continue;
}
if(Uno && Dos && !Tres) {
vector<int> V;
for(int i = 0; i < S[l].size(); i++) {
if(vis[S[l][i]]) continue;
V.push_back(S[l][i]); int Pr = S[l][i];
for(int j = i + 1; j < S[l].size(); j++) {
if(P[S[l][i]][S[l][j]] != 1) continue;
B[Pr][S[l][j]] = B[S[l][j]][Pr] = 1;
Pr = S[l][j]; vis[S[l][j]] = 1;
}
}
if(V.size() <= 2) return 0;
for(int l = 1; l < V.size(); l++)
B[V[l]][V[l - 1]] = B[V[l - 1]][V[l]] = 1;
B[V[0]][V[V.size() - 1]] = B[V[V.size() - 1]][V[0]] = 1;
continue;
}
return 0;
}
build(B);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:59:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i = 0; i < S[l].size(); i++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:60:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int j = i + 1; j < S[l].size(); j++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:65:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 1; i < S[l].size(); i++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:70:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 1; i < S[l].size(); i++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:79:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0; i < S[l].size(); i++) {
| ~~^~~~~~~~~~~~~
supertrees.cpp:82:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int j = i + 1; j < S[l].size(); j++) {
| ~~^~~~~~~~~~~~~
supertrees.cpp:89:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(int l = 1; l < V.size(); l++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
15 ms |
1184 KB |
Output is correct |
7 |
Correct |
210 ms |
22060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
15 ms |
1184 KB |
Output is correct |
7 |
Correct |
210 ms |
22060 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
13 ms |
1108 KB |
Output is correct |
13 |
Correct |
294 ms |
22080 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
724 KB |
Output is correct |
17 |
Correct |
112 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
5800 KB |
Output is correct |
21 |
Correct |
199 ms |
22100 KB |
Output is correct |
22 |
Correct |
240 ms |
22052 KB |
Output is correct |
23 |
Correct |
242 ms |
22028 KB |
Output is correct |
24 |
Correct |
213 ms |
22040 KB |
Output is correct |
25 |
Correct |
110 ms |
12192 KB |
Output is correct |
26 |
Correct |
73 ms |
12188 KB |
Output is correct |
27 |
Correct |
204 ms |
22060 KB |
Output is correct |
28 |
Correct |
183 ms |
22084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1124 KB |
Output is correct |
9 |
Correct |
169 ms |
22064 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
184 ms |
22000 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
82 ms |
12200 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 |
55 ms |
5732 KB |
Output is correct |
22 |
Correct |
178 ms |
22084 KB |
Output is correct |
23 |
Correct |
186 ms |
22052 KB |
Output is correct |
24 |
Correct |
192 ms |
22044 KB |
Output is correct |
25 |
Correct |
79 ms |
12196 KB |
Output is correct |
26 |
Correct |
77 ms |
12188 KB |
Output is correct |
27 |
Correct |
181 ms |
22056 KB |
Output is correct |
28 |
Correct |
181 ms |
22044 KB |
Output is correct |
29 |
Correct |
74 ms |
12072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
65 ms |
5788 KB |
Output is correct |
5 |
Correct |
175 ms |
22104 KB |
Output is correct |
6 |
Correct |
181 ms |
22092 KB |
Output is correct |
7 |
Correct |
199 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
45 ms |
5776 KB |
Output is correct |
10 |
Correct |
174 ms |
22000 KB |
Output is correct |
11 |
Correct |
185 ms |
22060 KB |
Output is correct |
12 |
Correct |
215 ms |
22092 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
51 ms |
5736 KB |
Output is correct |
17 |
Correct |
176 ms |
22092 KB |
Output is correct |
18 |
Correct |
182 ms |
22056 KB |
Output is correct |
19 |
Correct |
170 ms |
22056 KB |
Output is correct |
20 |
Correct |
176 ms |
22092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
15 ms |
1184 KB |
Output is correct |
7 |
Correct |
210 ms |
22060 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
13 ms |
1108 KB |
Output is correct |
13 |
Correct |
294 ms |
22080 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
724 KB |
Output is correct |
17 |
Correct |
112 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
5800 KB |
Output is correct |
21 |
Correct |
199 ms |
22100 KB |
Output is correct |
22 |
Correct |
240 ms |
22052 KB |
Output is correct |
23 |
Correct |
242 ms |
22028 KB |
Output is correct |
24 |
Correct |
213 ms |
22040 KB |
Output is correct |
25 |
Correct |
110 ms |
12192 KB |
Output is correct |
26 |
Correct |
73 ms |
12188 KB |
Output is correct |
27 |
Correct |
204 ms |
22060 KB |
Output is correct |
28 |
Correct |
183 ms |
22084 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1124 KB |
Output is correct |
37 |
Correct |
169 ms |
22064 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
184 ms |
22000 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
724 KB |
Output is correct |
45 |
Correct |
82 ms |
12200 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 |
55 ms |
5732 KB |
Output is correct |
50 |
Correct |
178 ms |
22084 KB |
Output is correct |
51 |
Correct |
186 ms |
22052 KB |
Output is correct |
52 |
Correct |
192 ms |
22044 KB |
Output is correct |
53 |
Correct |
79 ms |
12196 KB |
Output is correct |
54 |
Correct |
77 ms |
12188 KB |
Output is correct |
55 |
Correct |
181 ms |
22056 KB |
Output is correct |
56 |
Correct |
181 ms |
22044 KB |
Output is correct |
57 |
Correct |
74 ms |
12072 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
724 KB |
Output is correct |
61 |
Correct |
77 ms |
12192 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
46 ms |
5796 KB |
Output is correct |
66 |
Correct |
76 ms |
12108 KB |
Output is correct |
67 |
Correct |
75 ms |
12188 KB |
Output is correct |
68 |
Correct |
86 ms |
12192 KB |
Output is correct |
69 |
Correct |
68 ms |
12192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
15 ms |
1184 KB |
Output is correct |
7 |
Correct |
210 ms |
22060 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
13 ms |
1108 KB |
Output is correct |
13 |
Correct |
294 ms |
22080 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
724 KB |
Output is correct |
17 |
Correct |
112 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
5800 KB |
Output is correct |
21 |
Correct |
199 ms |
22100 KB |
Output is correct |
22 |
Correct |
240 ms |
22052 KB |
Output is correct |
23 |
Correct |
242 ms |
22028 KB |
Output is correct |
24 |
Correct |
213 ms |
22040 KB |
Output is correct |
25 |
Correct |
110 ms |
12192 KB |
Output is correct |
26 |
Correct |
73 ms |
12188 KB |
Output is correct |
27 |
Correct |
204 ms |
22060 KB |
Output is correct |
28 |
Correct |
183 ms |
22084 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1124 KB |
Output is correct |
37 |
Correct |
169 ms |
22064 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
184 ms |
22000 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
724 KB |
Output is correct |
45 |
Correct |
82 ms |
12200 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 |
55 ms |
5732 KB |
Output is correct |
50 |
Correct |
178 ms |
22084 KB |
Output is correct |
51 |
Correct |
186 ms |
22052 KB |
Output is correct |
52 |
Correct |
192 ms |
22044 KB |
Output is correct |
53 |
Correct |
79 ms |
12196 KB |
Output is correct |
54 |
Correct |
77 ms |
12188 KB |
Output is correct |
55 |
Correct |
181 ms |
22056 KB |
Output is correct |
56 |
Correct |
181 ms |
22044 KB |
Output is correct |
57 |
Correct |
74 ms |
12072 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
65 ms |
5788 KB |
Output is correct |
62 |
Correct |
175 ms |
22104 KB |
Output is correct |
63 |
Correct |
181 ms |
22092 KB |
Output is correct |
64 |
Correct |
199 ms |
22020 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
45 ms |
5776 KB |
Output is correct |
67 |
Correct |
174 ms |
22000 KB |
Output is correct |
68 |
Correct |
185 ms |
22060 KB |
Output is correct |
69 |
Correct |
215 ms |
22092 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
51 ms |
5736 KB |
Output is correct |
74 |
Correct |
176 ms |
22092 KB |
Output is correct |
75 |
Correct |
182 ms |
22056 KB |
Output is correct |
76 |
Correct |
170 ms |
22056 KB |
Output is correct |
77 |
Correct |
176 ms |
22092 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
724 KB |
Output is correct |
81 |
Correct |
77 ms |
12192 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
212 KB |
Output is correct |
84 |
Correct |
0 ms |
212 KB |
Output is correct |
85 |
Correct |
46 ms |
5796 KB |
Output is correct |
86 |
Correct |
76 ms |
12108 KB |
Output is correct |
87 |
Correct |
75 ms |
12188 KB |
Output is correct |
88 |
Correct |
86 ms |
12192 KB |
Output is correct |
89 |
Correct |
68 ms |
12192 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
5 ms |
744 KB |
Output is correct |
93 |
Correct |
116 ms |
12188 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
0 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
17 ms |
3240 KB |
Output is correct |
98 |
Correct |
74 ms |
12192 KB |
Output is correct |
99 |
Correct |
73 ms |
12108 KB |
Output is correct |
100 |
Correct |
78 ms |
12192 KB |
Output is correct |
101 |
Correct |
74 ms |
12192 KB |
Output is correct |
102 |
Correct |
74 ms |
12188 KB |
Output is correct |
103 |
Correct |
91 ms |
12072 KB |
Output is correct |
104 |
Correct |
80 ms |
12192 KB |
Output is correct |
105 |
Correct |
96 ms |
12196 KB |
Output is correct |