#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1e3 + 10;
int n, ds[maxn], ds1[maxn];
vector<int> vec[maxn], vec1[maxn];
int find(int v) {
if(v == ds[v]) return v;
return ds[v] = find(ds[v]);
}
void join(int u, int v) {
ds[v] = u;
for(auto x : vec[v]) vec[u].pb(x);
}
int find1(int v) {
if(v == ds1[v]) return v;
return ds1[v] = find1(ds1[v]);
}
void join1(int u, int v) {
ds1[v] = u;
for(auto x : vec1[v]) vec1[u].pb(x);
}
int construct(vector<vector<int>> p) {
n = p.size();
int ans = 1;
for(int i = 0; i < n; i++) {
ds[i] = i;
vec[i].pb(i);
}
//juntar os 1s
for(int i = 0; i < n; i++) {
for(int j = i+1; j < n; j++) {
if(p[i][j] == 1 && find(i) != find(j)) join(find(i),find(j));
}
}
for(int i = 0; i < n; i++) {
// cout << i << " " << find(i) << endl;
if(find(i) != i) continue;
//compara i com todos no vec dele
for(auto x : vec[i]) {
if(i == x) continue;
if(p[x][i] == 0) ans = 0;
for(int j = 0; j < n; j++) {
if(p[x][j] != p[i][j] && x != j && x != i) ans = 0;
}
}
}
for(int i = 0; i < n; i++) {
ds1[i] = i;
vec1[i].pb(i);
}
//junta os caras que sao pais e tem p[i][j] = 2
for(int i = 0; i < n; i++) {
for(int j = i+1; j < n; j++) {
if(p[i][j] != 2) continue;
int i1 = find1(find(i));
int j1 = find1(find(j));
if(i1 != j1) join1(i1,j1);
}
}
//testar se deu bom
for(int i = 0; i < n; i++) {
if(vec1[find1(find(i))].size() == 2) ans = 0;
for(int j = i+1; j < n; j++) {
if(find(i) == find(j)) {
if(p[i][j] != 1) ans = 0;
}
if(find1(find(i)) != find1(find(j))) {
if(p[i][j] != 0) ans = 0;
}
if(find1(find(i)) == find1(find(j)) && find(i) != find(j)) {
if(p[i][j] != 2) ans = 0;
}
}
}
if(ans == 0) return 0;
vector<vector<int>> b(n);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) b[i].pb(0);
}
//ligo com as arestas dos 1s
for(int i = 0; i < n; i++) {
if(find(i) != i) continue;
for(int j = 1; j < vec[i].size(); j++) {
b[vec[i][j-1]][vec[i][j]] = 1;
b[vec[i][j]][vec[i][j-1]] = 1;
}
}
//ligo as arestas dos 2s
for(int i = 0; i < n; i++) {
if(i != find1(find(i)) || vec1[i].size() == 1) continue;
for(int j = 0; j < vec1[i].size(); j++) {
b[vec1[i][j]][vec1[i][(j+1)%((int) vec1[i].size())]] = 1;
b[vec1[i][(j+1)%((int) vec1[i].size())]][vec1[i][j]] = 1;
}
}
build(b);
// for(int i = 0; i < n; i++) {
// for(int j = 0; j < n; j++) {
// cout << i << " " << j << " " << b[i][j] << endl;
// }
// }
return 1;
}
// int32_t main() {
// ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// // freopen("out.out", "w", stdout);
// int N;
// vector<vector<int>> p;
// cin >> N;
// p.resize(N);
// for(int i = 0; i < N; i++) {
// for(int j = 0; j < N; j++) {
// int x; cin >> x;
// p[i].pb(x);
// }
// }
// construct(p);
// }
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:124:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int j = 1; j < vec[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
supertrees.cpp:134:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
134 | for(int j = 0; j < vec1[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1388 KB |
Output is correct |
7 |
Correct |
191 ms |
24100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1388 KB |
Output is correct |
7 |
Correct |
191 ms |
24100 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
11 ms |
1248 KB |
Output is correct |
13 |
Correct |
180 ms |
24100 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
103 ms |
10240 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
46 ms |
6324 KB |
Output is correct |
21 |
Correct |
196 ms |
24228 KB |
Output is correct |
22 |
Correct |
188 ms |
24100 KB |
Output is correct |
23 |
Correct |
212 ms |
24120 KB |
Output is correct |
24 |
Correct |
216 ms |
24192 KB |
Output is correct |
25 |
Correct |
81 ms |
10188 KB |
Output is correct |
26 |
Correct |
76 ms |
10160 KB |
Output is correct |
27 |
Correct |
209 ms |
24172 KB |
Output is correct |
28 |
Correct |
182 ms |
24124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
356 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 |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
8 ms |
1364 KB |
Output is correct |
9 |
Correct |
188 ms |
24140 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
1364 KB |
Output is correct |
13 |
Correct |
194 ms |
24224 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
99 ms |
10264 KB |
Output is correct |
18 |
Correct |
1 ms |
340 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 |
6308 KB |
Output is correct |
22 |
Correct |
189 ms |
24160 KB |
Output is correct |
23 |
Correct |
209 ms |
24136 KB |
Output is correct |
24 |
Correct |
248 ms |
24164 KB |
Output is correct |
25 |
Correct |
76 ms |
10220 KB |
Output is correct |
26 |
Correct |
84 ms |
10148 KB |
Output is correct |
27 |
Correct |
232 ms |
24124 KB |
Output is correct |
28 |
Correct |
195 ms |
24188 KB |
Output is correct |
29 |
Correct |
85 ms |
10152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
47 ms |
6316 KB |
Output is correct |
5 |
Correct |
197 ms |
24252 KB |
Output is correct |
6 |
Correct |
186 ms |
24260 KB |
Output is correct |
7 |
Correct |
214 ms |
24212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
58 ms |
6308 KB |
Output is correct |
10 |
Correct |
209 ms |
24104 KB |
Output is correct |
11 |
Correct |
187 ms |
24108 KB |
Output is correct |
12 |
Correct |
236 ms |
24116 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
64 ms |
6296 KB |
Output is correct |
17 |
Correct |
189 ms |
24204 KB |
Output is correct |
18 |
Correct |
204 ms |
24208 KB |
Output is correct |
19 |
Correct |
199 ms |
24188 KB |
Output is correct |
20 |
Correct |
202 ms |
24152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1388 KB |
Output is correct |
7 |
Correct |
191 ms |
24100 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
11 ms |
1248 KB |
Output is correct |
13 |
Correct |
180 ms |
24100 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
103 ms |
10240 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
46 ms |
6324 KB |
Output is correct |
21 |
Correct |
196 ms |
24228 KB |
Output is correct |
22 |
Correct |
188 ms |
24100 KB |
Output is correct |
23 |
Correct |
212 ms |
24120 KB |
Output is correct |
24 |
Correct |
216 ms |
24192 KB |
Output is correct |
25 |
Correct |
81 ms |
10188 KB |
Output is correct |
26 |
Correct |
76 ms |
10160 KB |
Output is correct |
27 |
Correct |
209 ms |
24172 KB |
Output is correct |
28 |
Correct |
182 ms |
24124 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
356 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
8 ms |
1364 KB |
Output is correct |
37 |
Correct |
188 ms |
24140 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
1364 KB |
Output is correct |
41 |
Correct |
194 ms |
24224 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
99 ms |
10264 KB |
Output is correct |
46 |
Correct |
1 ms |
340 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 |
6308 KB |
Output is correct |
50 |
Correct |
189 ms |
24160 KB |
Output is correct |
51 |
Correct |
209 ms |
24136 KB |
Output is correct |
52 |
Correct |
248 ms |
24164 KB |
Output is correct |
53 |
Correct |
76 ms |
10220 KB |
Output is correct |
54 |
Correct |
84 ms |
10148 KB |
Output is correct |
55 |
Correct |
232 ms |
24124 KB |
Output is correct |
56 |
Correct |
195 ms |
24188 KB |
Output is correct |
57 |
Correct |
85 ms |
10152 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
6 ms |
724 KB |
Output is correct |
61 |
Correct |
96 ms |
10268 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 |
50 ms |
6348 KB |
Output is correct |
66 |
Correct |
90 ms |
10148 KB |
Output is correct |
67 |
Correct |
93 ms |
10164 KB |
Output is correct |
68 |
Correct |
81 ms |
10188 KB |
Output is correct |
69 |
Correct |
80 ms |
10152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1388 KB |
Output is correct |
7 |
Correct |
191 ms |
24100 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
11 ms |
1248 KB |
Output is correct |
13 |
Correct |
180 ms |
24100 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
103 ms |
10240 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
46 ms |
6324 KB |
Output is correct |
21 |
Correct |
196 ms |
24228 KB |
Output is correct |
22 |
Correct |
188 ms |
24100 KB |
Output is correct |
23 |
Correct |
212 ms |
24120 KB |
Output is correct |
24 |
Correct |
216 ms |
24192 KB |
Output is correct |
25 |
Correct |
81 ms |
10188 KB |
Output is correct |
26 |
Correct |
76 ms |
10160 KB |
Output is correct |
27 |
Correct |
209 ms |
24172 KB |
Output is correct |
28 |
Correct |
182 ms |
24124 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
356 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
8 ms |
1364 KB |
Output is correct |
37 |
Correct |
188 ms |
24140 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
1364 KB |
Output is correct |
41 |
Correct |
194 ms |
24224 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
99 ms |
10264 KB |
Output is correct |
46 |
Correct |
1 ms |
340 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 |
6308 KB |
Output is correct |
50 |
Correct |
189 ms |
24160 KB |
Output is correct |
51 |
Correct |
209 ms |
24136 KB |
Output is correct |
52 |
Correct |
248 ms |
24164 KB |
Output is correct |
53 |
Correct |
76 ms |
10220 KB |
Output is correct |
54 |
Correct |
84 ms |
10148 KB |
Output is correct |
55 |
Correct |
232 ms |
24124 KB |
Output is correct |
56 |
Correct |
195 ms |
24188 KB |
Output is correct |
57 |
Correct |
85 ms |
10152 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
47 ms |
6316 KB |
Output is correct |
62 |
Correct |
197 ms |
24252 KB |
Output is correct |
63 |
Correct |
186 ms |
24260 KB |
Output is correct |
64 |
Correct |
214 ms |
24212 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
58 ms |
6308 KB |
Output is correct |
67 |
Correct |
209 ms |
24104 KB |
Output is correct |
68 |
Correct |
187 ms |
24108 KB |
Output is correct |
69 |
Correct |
236 ms |
24116 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
352 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
64 ms |
6296 KB |
Output is correct |
74 |
Correct |
189 ms |
24204 KB |
Output is correct |
75 |
Correct |
204 ms |
24208 KB |
Output is correct |
76 |
Correct |
199 ms |
24188 KB |
Output is correct |
77 |
Correct |
202 ms |
24152 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
1 ms |
348 KB |
Output is correct |
80 |
Correct |
6 ms |
724 KB |
Output is correct |
81 |
Correct |
96 ms |
10268 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 |
50 ms |
6348 KB |
Output is correct |
86 |
Correct |
90 ms |
10148 KB |
Output is correct |
87 |
Correct |
93 ms |
10164 KB |
Output is correct |
88 |
Correct |
81 ms |
10188 KB |
Output is correct |
89 |
Correct |
80 ms |
10152 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
340 KB |
Output is correct |
92 |
Correct |
5 ms |
724 KB |
Output is correct |
93 |
Correct |
100 ms |
10164 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
340 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
20 ms |
2856 KB |
Output is correct |
98 |
Correct |
94 ms |
10148 KB |
Output is correct |
99 |
Correct |
103 ms |
10256 KB |
Output is correct |
100 |
Correct |
85 ms |
10152 KB |
Output is correct |
101 |
Correct |
75 ms |
10156 KB |
Output is correct |
102 |
Correct |
77 ms |
10160 KB |
Output is correct |
103 |
Correct |
83 ms |
10164 KB |
Output is correct |
104 |
Correct |
93 ms |
10232 KB |
Output is correct |
105 |
Correct |
90 ms |
10148 KB |
Output is correct |