#include "supertrees.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, k;
vector<vector<int>>a, d;
vector<int>c, fst, lst, gic;
vector<bool>used, kagic;
vector<bool>mej;
const int INF = 1e9 + 7;
int construct(vector<vector<int>> p) {
n = p.size();
a = p;
c.resize(n, INF);
fst.resize(n, -1);
lst.resize(n, -1);
gic.resize(n, INF);
d.resize(n);
for (int i = 0; i < n; i++) {
d[i].resize(n, 0);
}
used.resize(n, false);
mej.resize(n, true);
kagic.resize(n, false);
bool ent1 = true;
bool ent2 = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 3)return 0;
if (p[i][j] != 0 && p[i][j] != 1) {
ent1 = false;
}
if (i != j && (p[i][j] != 0 && p[i][j] != 2)) {
ent2 = false;
}
}
}
int cur = 0;
for (int v = 0; v < n; v++) {
if (c[v] == INF) {
c[v] = cur++;
}
for (int to = 0; to < n; to++) {
if (p[v][to] == 2 || p[v][to] == 1) {
if (c[to] != INF && c[to] != c[v]) {
return 0;
}
c[to] = c[v];
}
else if (p[v][to] == 0) {
if (c[to] == c[v])return 0;
}
}
}
for (int v = 0; v < n; v++) {
for (int to = 0; to < n; to++) {
if (to != v && p[v][to] == 1) {
mej[v] = false;
break;
}
}
}
for (int v = 0; v < n; v++) {
if (mej[v]) {
//cout << "Cikli mej a: " << v << endl;
used[v] = true;
if (fst[c[v]] == -1) {
fst[c[v]] = v;
}
lst[c[v]] = v;
for (int to = v + 1; to < n; to++) {
if (c[to] == c[v] && mej[to]) {
d[v][to] = d[to][v] = 1;
//cout << "Kpan1: " << v << " " << to << endl;
break;
}
}
}
}
int curgic = 0;
for (int v = 0; v < n; v++) {
if (!used[v]) {
if (gic[v] == INF) {
gic[v] = curgic++;
}
kagic[c[v]] = true;
for (int to = 0; to < n; to++) {
if (p[v][to] == 1) {
if (gic[to] != INF && gic[to] != gic[v]) {
return 0;
}
gic[to] = gic[v];
}
else if (p[v][to] == 2 && gic[to] == gic[v]) {
return 0;
}
}
}
}
for (int v = 0; v < n; v++) {
if (!used[v]) {
bool ok = false;
for (int to = v + 1; to < n; to++) {
if (c[to] == c[v] && gic[to] == gic[v]) {
d[v][to] = d[to][v] = 1;
//cout << "Kpan2: " << v << " " << to << endl;
ok = true;
break;
}
}
if (!ok) {
//cout << "Verjiny " << c[v] << " guyni " << gic[v] << " toxi: " << v << endl;
int to = fst[c[v]];
if (to != v && to != -1) {
if (d[to][v] == 1)return 0;
d[to][v] = d[v][to] = 1;
//cout << "Kpan3: " << v << " " << to << endl;
}
if (lst[c[v]] == -1) {
lst[c[v]] = v;
}
fst[c[v]] = v;
}
////cout << v << endl;
}
}
for (int i = 0; i < n; i++) {
if (fst[i] == lst[i])continue;
if (d[fst[i]][lst[i]])return 0;
d[fst[i]][lst[i]] = d[lst[i]][fst[i]] = 1;
}
//return 1;
//cout << "3: " << c[3] << " " << gic[3] << " " << used[3] << endl;
build(d);
return 1;
}
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
6
1 1 2 2 2 2
1 1 2 2 2 2
2 2 1 2 2 1
2 2 2 1 1 2
2 2 2 1 1 2
2 2 1 2 2 1
*/
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:34:7: warning: variable 'ent1' set but not used [-Wunused-but-set-variable]
34 | bool ent1 = true;
| ^~~~
supertrees.cpp:35:7: warning: variable 'ent2' set but not used [-Wunused-but-set-variable]
35 | bool ent2 = true;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
296 KB |
Output is correct |
6 |
Correct |
11 ms |
1364 KB |
Output is correct |
7 |
Correct |
171 ms |
26096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
296 KB |
Output is correct |
6 |
Correct |
11 ms |
1364 KB |
Output is correct |
7 |
Correct |
171 ms |
26096 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1364 KB |
Output is correct |
13 |
Correct |
188 ms |
26156 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
102 ms |
16132 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
42 ms |
6856 KB |
Output is correct |
21 |
Correct |
202 ms |
26196 KB |
Output is correct |
22 |
Correct |
175 ms |
26120 KB |
Output is correct |
23 |
Correct |
180 ms |
26124 KB |
Output is correct |
24 |
Correct |
182 ms |
26116 KB |
Output is correct |
25 |
Correct |
74 ms |
16204 KB |
Output is correct |
26 |
Correct |
76 ms |
16160 KB |
Output is correct |
27 |
Correct |
175 ms |
26092 KB |
Output is correct |
28 |
Correct |
208 ms |
26204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
292 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
8 ms |
1436 KB |
Output is correct |
9 |
Correct |
197 ms |
26060 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 |
1364 KB |
Output is correct |
13 |
Correct |
175 ms |
26044 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
83 ms |
16140 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
44 ms |
6792 KB |
Output is correct |
22 |
Correct |
195 ms |
26148 KB |
Output is correct |
23 |
Correct |
166 ms |
26080 KB |
Output is correct |
24 |
Correct |
176 ms |
26124 KB |
Output is correct |
25 |
Correct |
72 ms |
16132 KB |
Output is correct |
26 |
Correct |
73 ms |
16140 KB |
Output is correct |
27 |
Correct |
173 ms |
26108 KB |
Output is correct |
28 |
Correct |
172 ms |
26120 KB |
Output is correct |
29 |
Correct |
73 ms |
16132 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 |
44 ms |
6816 KB |
Output is correct |
5 |
Correct |
180 ms |
26096 KB |
Output is correct |
6 |
Correct |
165 ms |
26116 KB |
Output is correct |
7 |
Correct |
192 ms |
26060 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
43 ms |
6812 KB |
Output is correct |
10 |
Correct |
169 ms |
26112 KB |
Output is correct |
11 |
Correct |
165 ms |
26016 KB |
Output is correct |
12 |
Correct |
184 ms |
26128 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
44 ms |
6780 KB |
Output is correct |
17 |
Correct |
211 ms |
26400 KB |
Output is correct |
18 |
Correct |
169 ms |
26372 KB |
Output is correct |
19 |
Correct |
181 ms |
26296 KB |
Output is correct |
20 |
Correct |
166 ms |
26296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
296 KB |
Output is correct |
6 |
Correct |
11 ms |
1364 KB |
Output is correct |
7 |
Correct |
171 ms |
26096 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1364 KB |
Output is correct |
13 |
Correct |
188 ms |
26156 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
102 ms |
16132 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
42 ms |
6856 KB |
Output is correct |
21 |
Correct |
202 ms |
26196 KB |
Output is correct |
22 |
Correct |
175 ms |
26120 KB |
Output is correct |
23 |
Correct |
180 ms |
26124 KB |
Output is correct |
24 |
Correct |
182 ms |
26116 KB |
Output is correct |
25 |
Correct |
74 ms |
16204 KB |
Output is correct |
26 |
Correct |
76 ms |
16160 KB |
Output is correct |
27 |
Correct |
175 ms |
26092 KB |
Output is correct |
28 |
Correct |
208 ms |
26204 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
292 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
300 KB |
Output is correct |
36 |
Correct |
8 ms |
1436 KB |
Output is correct |
37 |
Correct |
197 ms |
26060 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 |
1364 KB |
Output is correct |
41 |
Correct |
175 ms |
26044 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
83 ms |
16140 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
308 KB |
Output is correct |
48 |
Correct |
1 ms |
300 KB |
Output is correct |
49 |
Correct |
44 ms |
6792 KB |
Output is correct |
50 |
Correct |
195 ms |
26148 KB |
Output is correct |
51 |
Correct |
166 ms |
26080 KB |
Output is correct |
52 |
Correct |
176 ms |
26124 KB |
Output is correct |
53 |
Correct |
72 ms |
16132 KB |
Output is correct |
54 |
Correct |
73 ms |
16140 KB |
Output is correct |
55 |
Correct |
173 ms |
26108 KB |
Output is correct |
56 |
Correct |
172 ms |
26120 KB |
Output is correct |
57 |
Correct |
73 ms |
16132 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
296 KB |
Output is correct |
60 |
Correct |
4 ms |
920 KB |
Output is correct |
61 |
Correct |
82 ms |
16132 KB |
Output is correct |
62 |
Correct |
1 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 |
44 ms |
6784 KB |
Output is correct |
66 |
Correct |
76 ms |
16468 KB |
Output is correct |
67 |
Correct |
76 ms |
16436 KB |
Output is correct |
68 |
Correct |
80 ms |
16388 KB |
Output is correct |
69 |
Correct |
85 ms |
16384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
296 KB |
Output is correct |
6 |
Correct |
11 ms |
1364 KB |
Output is correct |
7 |
Correct |
171 ms |
26096 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1364 KB |
Output is correct |
13 |
Correct |
188 ms |
26156 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
102 ms |
16132 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
42 ms |
6856 KB |
Output is correct |
21 |
Correct |
202 ms |
26196 KB |
Output is correct |
22 |
Correct |
175 ms |
26120 KB |
Output is correct |
23 |
Correct |
180 ms |
26124 KB |
Output is correct |
24 |
Correct |
182 ms |
26116 KB |
Output is correct |
25 |
Correct |
74 ms |
16204 KB |
Output is correct |
26 |
Correct |
76 ms |
16160 KB |
Output is correct |
27 |
Correct |
175 ms |
26092 KB |
Output is correct |
28 |
Correct |
208 ms |
26204 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
292 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
300 KB |
Output is correct |
36 |
Correct |
8 ms |
1436 KB |
Output is correct |
37 |
Correct |
197 ms |
26060 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 |
1364 KB |
Output is correct |
41 |
Correct |
175 ms |
26044 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
83 ms |
16140 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
308 KB |
Output is correct |
48 |
Correct |
1 ms |
300 KB |
Output is correct |
49 |
Correct |
44 ms |
6792 KB |
Output is correct |
50 |
Correct |
195 ms |
26148 KB |
Output is correct |
51 |
Correct |
166 ms |
26080 KB |
Output is correct |
52 |
Correct |
176 ms |
26124 KB |
Output is correct |
53 |
Correct |
72 ms |
16132 KB |
Output is correct |
54 |
Correct |
73 ms |
16140 KB |
Output is correct |
55 |
Correct |
173 ms |
26108 KB |
Output is correct |
56 |
Correct |
172 ms |
26120 KB |
Output is correct |
57 |
Correct |
73 ms |
16132 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
44 ms |
6816 KB |
Output is correct |
62 |
Correct |
180 ms |
26096 KB |
Output is correct |
63 |
Correct |
165 ms |
26116 KB |
Output is correct |
64 |
Correct |
192 ms |
26060 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
43 ms |
6812 KB |
Output is correct |
67 |
Correct |
169 ms |
26112 KB |
Output is correct |
68 |
Correct |
165 ms |
26016 KB |
Output is correct |
69 |
Correct |
184 ms |
26128 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
44 ms |
6780 KB |
Output is correct |
74 |
Correct |
211 ms |
26400 KB |
Output is correct |
75 |
Correct |
169 ms |
26372 KB |
Output is correct |
76 |
Correct |
181 ms |
26296 KB |
Output is correct |
77 |
Correct |
166 ms |
26296 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
296 KB |
Output is correct |
80 |
Correct |
4 ms |
920 KB |
Output is correct |
81 |
Correct |
82 ms |
16132 KB |
Output is correct |
82 |
Correct |
1 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 |
44 ms |
6784 KB |
Output is correct |
86 |
Correct |
76 ms |
16468 KB |
Output is correct |
87 |
Correct |
76 ms |
16436 KB |
Output is correct |
88 |
Correct |
80 ms |
16388 KB |
Output is correct |
89 |
Correct |
85 ms |
16384 KB |
Output is correct |
90 |
Correct |
0 ms |
296 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
980 KB |
Output is correct |
93 |
Correct |
77 ms |
16388 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
22 ms |
4556 KB |
Output is correct |
98 |
Correct |
78 ms |
16472 KB |
Output is correct |
99 |
Correct |
73 ms |
16388 KB |
Output is correct |
100 |
Correct |
70 ms |
16400 KB |
Output is correct |
101 |
Correct |
69 ms |
16404 KB |
Output is correct |
102 |
Correct |
69 ms |
16388 KB |
Output is correct |
103 |
Correct |
74 ms |
16392 KB |
Output is correct |
104 |
Correct |
75 ms |
16400 KB |
Output is correct |
105 |
Correct |
91 ms |
16480 KB |
Output is correct |