#include <bits/stdc++.h>
//#include "grader.cpp"
#include "supertrees.h"
#define sz(x) (int)x.size()
#define pb push_back
using namespace std;
const int N = 1e3 + 500;
int pr[N];
int prl[N];
int f(int v) {return (pr[v] == v ? v : pr[v] = f(pr[v]));}
void link(int a, int b) {
a = f(a); b = f(b);
if (a == b) {
return;
}
pr[a] = b;
}
int fl(int v) {return (prl[v] == v ? v : prl[v] = fl(prl[v]));}
void linkl(int a, int b) {
a = fl(a); b = fl(b);
if (a == b) {
return;
}
prl[a] = b;
}
int construct(vector <vector <int> > p) {
int n = sz(p);
for (int i = 0; i < n; i++) {
pr[i] = i;
prl[i] = i;
}
vector <int> cnt(4, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 1 && i != j) {
link(i, j);
}
cnt[p[i][j]]++;
if (p[i][j] > 0 && i != j) {
linkl(i, j);
}
}
}
if (cnt[2] && cnt[3]) {
return 0;
}
vector <vector <int> > b(n, vector <int> (n, 0));
vector <set<int> > cp(n);
set<int> cpp;
for (int i = 0; i < n; i++) {
cp[fl(i)].insert(i);
cpp.insert(fl(i));
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (fl(i) == fl(j) && !p[i][j]) {
return 0;
}
}
}
vector <int> used(n, 0);
for (auto pp : cpp) {
set <int> cyc;
vector <int> c;
for (auto i : cp[pp]) {
if (cyc.count(f(i))) {
continue;
}
cyc.insert(f(i));
c.pb(i);
}
if (cnt[3] && (sz(cyc) == 3 || sz(cyc) == 2)) {
return 0;
}
if (cnt[2] && sz(cyc) == 2) {
return 0;
}
for (int i = 0; i < sz(c); i++) {
b[c[i]][c[(i + 1) % sz(c)]] = 1;
b[c[(i + 1) % sz(c)]][c[i]] = 1;
}
if (cnt[3]) {
b[c[1]][c[2]] = 1;
b[c[2]][c[1]] = 1;
}
vector <vector <int> > cmp(n);
set <int> cmps;
for (auto i : cp[pp]) {
cmp[f(i)].pb(i);
cmps.insert(f(i));
}
int it = 0;
for (auto i : cp[pp]) {
if (sz(cmp[i])) {
int last = cmp[i][0];
for (auto x : cmp[i]) {
if (x == last) {
continue;
}
b[last][x] = 1;
b[x][last] = 1;
last = x;
}
}
}
}
for (int i = 0; i < n; i++) {
b[i][i] = 0;
}
build(b);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:106:13: warning: unused variable 'it' [-Wunused-variable]
106 | int it = 0;
| ^~
# |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
8 ms |
1168 KB |
Output is correct |
7 |
Correct |
192 ms |
22060 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
8 ms |
1168 KB |
Output is correct |
7 |
Correct |
192 ms |
22060 KB |
Output is correct |
8 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
172 ms |
22160 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
90 ms |
12180 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
5776 KB |
Output is correct |
21 |
Correct |
186 ms |
22064 KB |
Output is correct |
22 |
Correct |
175 ms |
22164 KB |
Output is correct |
23 |
Correct |
193 ms |
22372 KB |
Output is correct |
24 |
Correct |
186 ms |
22148 KB |
Output is correct |
25 |
Correct |
79 ms |
12168 KB |
Output is correct |
26 |
Correct |
83 ms |
12164 KB |
Output is correct |
27 |
Correct |
197 ms |
22092 KB |
Output is correct |
28 |
Correct |
177 ms |
22152 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
7 ms |
1240 KB |
Output is correct |
9 |
Correct |
172 ms |
22152 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
174 ms |
22152 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
87 ms |
12236 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
232 KB |
Output is correct |
21 |
Correct |
45 ms |
6224 KB |
Output is correct |
22 |
Correct |
175 ms |
24072 KB |
Output is correct |
23 |
Correct |
193 ms |
24164 KB |
Output is correct |
24 |
Correct |
184 ms |
24100 KB |
Output is correct |
25 |
Correct |
75 ms |
14204 KB |
Output is correct |
26 |
Correct |
73 ms |
14076 KB |
Output is correct |
27 |
Correct |
182 ms |
24064 KB |
Output is correct |
28 |
Correct |
195 ms |
24056 KB |
Output is correct |
29 |
Correct |
103 ms |
14208 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
45 ms |
5708 KB |
Output is correct |
5 |
Correct |
199 ms |
22060 KB |
Output is correct |
6 |
Correct |
179 ms |
22100 KB |
Output is correct |
7 |
Correct |
207 ms |
22112 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
55 ms |
6204 KB |
Output is correct |
10 |
Correct |
181 ms |
24176 KB |
Output is correct |
11 |
Correct |
172 ms |
24064 KB |
Output is correct |
12 |
Correct |
190 ms |
24108 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 |
300 KB |
Output is correct |
16 |
Correct |
48 ms |
6264 KB |
Output is correct |
17 |
Correct |
172 ms |
24052 KB |
Output is correct |
18 |
Correct |
222 ms |
24012 KB |
Output is correct |
19 |
Correct |
175 ms |
24020 KB |
Output is correct |
20 |
Correct |
193 ms |
24156 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
8 ms |
1168 KB |
Output is correct |
7 |
Correct |
192 ms |
22060 KB |
Output is correct |
8 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
172 ms |
22160 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
90 ms |
12180 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
5776 KB |
Output is correct |
21 |
Correct |
186 ms |
22064 KB |
Output is correct |
22 |
Correct |
175 ms |
22164 KB |
Output is correct |
23 |
Correct |
193 ms |
22372 KB |
Output is correct |
24 |
Correct |
186 ms |
22148 KB |
Output is correct |
25 |
Correct |
79 ms |
12168 KB |
Output is correct |
26 |
Correct |
83 ms |
12164 KB |
Output is correct |
27 |
Correct |
197 ms |
22092 KB |
Output is correct |
28 |
Correct |
177 ms |
22152 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 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 |
7 ms |
1240 KB |
Output is correct |
37 |
Correct |
172 ms |
22152 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1236 KB |
Output is correct |
41 |
Correct |
174 ms |
22152 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
87 ms |
12236 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
232 KB |
Output is correct |
49 |
Correct |
45 ms |
6224 KB |
Output is correct |
50 |
Correct |
175 ms |
24072 KB |
Output is correct |
51 |
Correct |
193 ms |
24164 KB |
Output is correct |
52 |
Correct |
184 ms |
24100 KB |
Output is correct |
53 |
Correct |
75 ms |
14204 KB |
Output is correct |
54 |
Correct |
73 ms |
14076 KB |
Output is correct |
55 |
Correct |
182 ms |
24064 KB |
Output is correct |
56 |
Correct |
195 ms |
24056 KB |
Output is correct |
57 |
Correct |
103 ms |
14208 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
304 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
102 ms |
14156 KB |
Output is correct |
62 |
Correct |
1 ms |
308 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
46 ms |
6308 KB |
Output is correct |
66 |
Correct |
77 ms |
14080 KB |
Output is correct |
67 |
Correct |
78 ms |
14092 KB |
Output is correct |
68 |
Correct |
85 ms |
14288 KB |
Output is correct |
69 |
Correct |
73 ms |
14216 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
8 ms |
1168 KB |
Output is correct |
7 |
Correct |
192 ms |
22060 KB |
Output is correct |
8 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
172 ms |
22160 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
90 ms |
12180 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
5776 KB |
Output is correct |
21 |
Correct |
186 ms |
22064 KB |
Output is correct |
22 |
Correct |
175 ms |
22164 KB |
Output is correct |
23 |
Correct |
193 ms |
22372 KB |
Output is correct |
24 |
Correct |
186 ms |
22148 KB |
Output is correct |
25 |
Correct |
79 ms |
12168 KB |
Output is correct |
26 |
Correct |
83 ms |
12164 KB |
Output is correct |
27 |
Correct |
197 ms |
22092 KB |
Output is correct |
28 |
Correct |
177 ms |
22152 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 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 |
7 ms |
1240 KB |
Output is correct |
37 |
Correct |
172 ms |
22152 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1236 KB |
Output is correct |
41 |
Correct |
174 ms |
22152 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
87 ms |
12236 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
232 KB |
Output is correct |
49 |
Correct |
45 ms |
6224 KB |
Output is correct |
50 |
Correct |
175 ms |
24072 KB |
Output is correct |
51 |
Correct |
193 ms |
24164 KB |
Output is correct |
52 |
Correct |
184 ms |
24100 KB |
Output is correct |
53 |
Correct |
75 ms |
14204 KB |
Output is correct |
54 |
Correct |
73 ms |
14076 KB |
Output is correct |
55 |
Correct |
182 ms |
24064 KB |
Output is correct |
56 |
Correct |
195 ms |
24056 KB |
Output is correct |
57 |
Correct |
103 ms |
14208 KB |
Output is correct |
58 |
Correct |
0 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 |
45 ms |
5708 KB |
Output is correct |
62 |
Correct |
199 ms |
22060 KB |
Output is correct |
63 |
Correct |
179 ms |
22100 KB |
Output is correct |
64 |
Correct |
207 ms |
22112 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
55 ms |
6204 KB |
Output is correct |
67 |
Correct |
181 ms |
24176 KB |
Output is correct |
68 |
Correct |
172 ms |
24064 KB |
Output is correct |
69 |
Correct |
190 ms |
24108 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 |
300 KB |
Output is correct |
73 |
Correct |
48 ms |
6264 KB |
Output is correct |
74 |
Correct |
172 ms |
24052 KB |
Output is correct |
75 |
Correct |
222 ms |
24012 KB |
Output is correct |
76 |
Correct |
175 ms |
24020 KB |
Output is correct |
77 |
Correct |
193 ms |
24156 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
304 KB |
Output is correct |
80 |
Correct |
4 ms |
852 KB |
Output is correct |
81 |
Correct |
102 ms |
14156 KB |
Output is correct |
82 |
Correct |
1 ms |
308 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
46 ms |
6308 KB |
Output is correct |
86 |
Correct |
77 ms |
14080 KB |
Output is correct |
87 |
Correct |
78 ms |
14092 KB |
Output is correct |
88 |
Correct |
85 ms |
14288 KB |
Output is correct |
89 |
Correct |
73 ms |
14216 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
700 KB |
Output is correct |
93 |
Correct |
83 ms |
10108 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 |
17 ms |
2684 KB |
Output is correct |
98 |
Correct |
74 ms |
10108 KB |
Output is correct |
99 |
Correct |
73 ms |
10120 KB |
Output is correct |
100 |
Correct |
70 ms |
10192 KB |
Output is correct |
101 |
Correct |
74 ms |
10060 KB |
Output is correct |
102 |
Incorrect |
177 ms |
24056 KB |
Answer gives possible 1 while actual possible 0 |
103 |
Halted |
0 ms |
0 KB |
- |