#include"supertrees.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
vvi L;
vi K;
vi F;
int find(int a) {return (F[a] == -1 ? a : F[a] = find(F[a]));}
void uunion(int a, int b) {
a = find(a); b = find(b);
if (a == b) return;
F[a] = b;
}
int oink(vvi p) {
int n = p.size();
vvi Adj(n, vi(n, 0));
L.clear(); F.clear(); F.resize(n, -1);
K.clear(); K.resize(n, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (p[i][j]) {
if (p[i][j] == 1) {K[i] = j;}
uunion(i, j);
continue;
}
//cerr << i << " " << j << " " << find(i) << " " << find(j) << endl;
if (find(i) == find(j)) return 0;
}
}
L.resize(n);
for (int i = 0; i < n; i++) {
L[find(i)].push_back(i);
}
//cerr << endl;
for (auto i : L) {
/*
for (auto j : i) {
cerr << j << " ";
}
cerr << endl;
//*/
if (i.size() < 2) continue;
if (i.size() == 2) {
int a = i[0], b = i[1];
if (p[a][b] == 2) return 0;
Adj[a][b] = 1;
Adj[b][a] = 1;
continue;
}
int l = i[i.size()-1];
for (int j = 0; j < i.size(); j++) {
int a = i[j];
//cerr << l << " " << a << " " << K[a] << " " << j << endl;
if (l == a) break;
if (K[a] <= a) {
Adj[l][a] = 1;
Adj[a][l] = 1;
l = a;
continue;
}
Adj[K[a]][a] = 1;
Adj[a][K[a]] = 1;
}
}
build(Adj);
return 1;
}
int oinkoink(vvi p) {
int n = p.size();
vvi Adj(n, vi(n, 0));
F.clear(); F.resize(n, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j]) {
if (find(i) == find(j)) continue;
Adj[i][j] = 1;
Adj[j][i] = 1;
uunion(i, j);
continue;
}
//cerr << i << " " << j << " " << find(i) << " " << find(j) << endl;
if (find(i) == find(j)) return 0;
}
}
build(Adj);
return 1;
}
int construct(std::vector<std::vector<int>> p) {
return oink(p);
}
Compilation message
supertrees.cpp: In function 'int oink(std::vector<std::vector<int> >)':
supertrees.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int j = 0; j < i.size(); 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
151 ms |
26104 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
151 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
153 ms |
26144 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
67 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
41 ms |
6904 KB |
Output is correct |
21 |
Correct |
160 ms |
25940 KB |
Output is correct |
22 |
Correct |
152 ms |
26388 KB |
Output is correct |
23 |
Correct |
156 ms |
25936 KB |
Output is correct |
24 |
Correct |
160 ms |
25976 KB |
Output is correct |
25 |
Correct |
68 ms |
16148 KB |
Output is correct |
26 |
Correct |
63 ms |
16212 KB |
Output is correct |
27 |
Correct |
160 ms |
25936 KB |
Output is correct |
28 |
Correct |
153 ms |
25940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
1432 KB |
Output is correct |
9 |
Correct |
157 ms |
26008 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
154 ms |
26068 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
67 ms |
16156 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
548 KB |
Output is correct |
21 |
Correct |
39 ms |
6860 KB |
Output is correct |
22 |
Correct |
160 ms |
26292 KB |
Output is correct |
23 |
Correct |
166 ms |
26092 KB |
Output is correct |
24 |
Correct |
156 ms |
26088 KB |
Output is correct |
25 |
Correct |
65 ms |
16136 KB |
Output is correct |
26 |
Correct |
70 ms |
16208 KB |
Output is correct |
27 |
Correct |
171 ms |
26004 KB |
Output is correct |
28 |
Correct |
157 ms |
26152 KB |
Output is correct |
29 |
Correct |
71 ms |
16136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
45 ms |
6748 KB |
Output is correct |
5 |
Correct |
161 ms |
26100 KB |
Output is correct |
6 |
Correct |
153 ms |
25940 KB |
Output is correct |
7 |
Correct |
174 ms |
25936 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
39 ms |
6700 KB |
Output is correct |
10 |
Correct |
157 ms |
26256 KB |
Output is correct |
11 |
Correct |
160 ms |
26104 KB |
Output is correct |
12 |
Correct |
171 ms |
26120 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 |
348 KB |
Output is correct |
16 |
Correct |
45 ms |
7360 KB |
Output is correct |
17 |
Correct |
155 ms |
27900 KB |
Output is correct |
18 |
Correct |
158 ms |
28048 KB |
Output is correct |
19 |
Correct |
171 ms |
28040 KB |
Output is correct |
20 |
Correct |
152 ms |
28160 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
151 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
153 ms |
26144 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
67 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
41 ms |
6904 KB |
Output is correct |
21 |
Correct |
160 ms |
25940 KB |
Output is correct |
22 |
Correct |
152 ms |
26388 KB |
Output is correct |
23 |
Correct |
156 ms |
25936 KB |
Output is correct |
24 |
Correct |
160 ms |
25976 KB |
Output is correct |
25 |
Correct |
68 ms |
16148 KB |
Output is correct |
26 |
Correct |
63 ms |
16212 KB |
Output is correct |
27 |
Correct |
160 ms |
25936 KB |
Output is correct |
28 |
Correct |
153 ms |
25940 KB |
Output is correct |
29 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
7 ms |
1432 KB |
Output is correct |
37 |
Correct |
157 ms |
26008 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
154 ms |
26068 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
67 ms |
16156 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
548 KB |
Output is correct |
49 |
Correct |
39 ms |
6860 KB |
Output is correct |
50 |
Correct |
160 ms |
26292 KB |
Output is correct |
51 |
Correct |
166 ms |
26092 KB |
Output is correct |
52 |
Correct |
156 ms |
26088 KB |
Output is correct |
53 |
Correct |
65 ms |
16136 KB |
Output is correct |
54 |
Correct |
70 ms |
16208 KB |
Output is correct |
55 |
Correct |
171 ms |
26004 KB |
Output is correct |
56 |
Correct |
157 ms |
26152 KB |
Output is correct |
57 |
Correct |
71 ms |
16136 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
67 ms |
16136 KB |
Output is correct |
62 |
Correct |
1 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 |
39 ms |
7272 KB |
Output is correct |
66 |
Correct |
66 ms |
18176 KB |
Output is correct |
67 |
Correct |
64 ms |
18000 KB |
Output is correct |
68 |
Correct |
78 ms |
18180 KB |
Output is correct |
69 |
Correct |
65 ms |
18024 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
151 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
153 ms |
26144 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
67 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
41 ms |
6904 KB |
Output is correct |
21 |
Correct |
160 ms |
25940 KB |
Output is correct |
22 |
Correct |
152 ms |
26388 KB |
Output is correct |
23 |
Correct |
156 ms |
25936 KB |
Output is correct |
24 |
Correct |
160 ms |
25976 KB |
Output is correct |
25 |
Correct |
68 ms |
16148 KB |
Output is correct |
26 |
Correct |
63 ms |
16212 KB |
Output is correct |
27 |
Correct |
160 ms |
25936 KB |
Output is correct |
28 |
Correct |
153 ms |
25940 KB |
Output is correct |
29 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
7 ms |
1432 KB |
Output is correct |
37 |
Correct |
157 ms |
26008 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
154 ms |
26068 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
67 ms |
16156 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
548 KB |
Output is correct |
49 |
Correct |
39 ms |
6860 KB |
Output is correct |
50 |
Correct |
160 ms |
26292 KB |
Output is correct |
51 |
Correct |
166 ms |
26092 KB |
Output is correct |
52 |
Correct |
156 ms |
26088 KB |
Output is correct |
53 |
Correct |
65 ms |
16136 KB |
Output is correct |
54 |
Correct |
70 ms |
16208 KB |
Output is correct |
55 |
Correct |
171 ms |
26004 KB |
Output is correct |
56 |
Correct |
157 ms |
26152 KB |
Output is correct |
57 |
Correct |
71 ms |
16136 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
45 ms |
6748 KB |
Output is correct |
62 |
Correct |
161 ms |
26100 KB |
Output is correct |
63 |
Correct |
153 ms |
25940 KB |
Output is correct |
64 |
Correct |
174 ms |
25936 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
39 ms |
6700 KB |
Output is correct |
67 |
Correct |
157 ms |
26256 KB |
Output is correct |
68 |
Correct |
160 ms |
26104 KB |
Output is correct |
69 |
Correct |
171 ms |
26120 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 |
348 KB |
Output is correct |
73 |
Correct |
45 ms |
7360 KB |
Output is correct |
74 |
Correct |
155 ms |
27900 KB |
Output is correct |
75 |
Correct |
158 ms |
28048 KB |
Output is correct |
76 |
Correct |
171 ms |
28040 KB |
Output is correct |
77 |
Correct |
152 ms |
28160 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
860 KB |
Output is correct |
81 |
Correct |
67 ms |
16136 KB |
Output is correct |
82 |
Correct |
1 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 |
39 ms |
7272 KB |
Output is correct |
86 |
Correct |
66 ms |
18176 KB |
Output is correct |
87 |
Correct |
64 ms |
18000 KB |
Output is correct |
88 |
Correct |
78 ms |
18180 KB |
Output is correct |
89 |
Correct |
65 ms |
18024 KB |
Output is correct |
90 |
Correct |
1 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
4 ms |
1116 KB |
Output is correct |
93 |
Correct |
73 ms |
18044 KB |
Output is correct |
94 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
95 |
Halted |
0 ms |
0 KB |
- |