#include "supertrees.h"
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define univ(V) (V).erase(unique(allv(V)),(V).end())
using namespace std;
typedef pair<int, int> pii;
int construct(vector<vector<int>> A) {
int N = A.size();
for(int i = N; i--;) for(int j = N; j--;)
if(2 < A[i][j]) return 0;
vector<int> B(N, -1);
for(int i = 0; i < N; i++) if(B[i] < 0) {
for(int j = i; j < N; j++) if(1 == A[i][j]) B[j] = i;
}
vector<vector<int>> Cy, Co;
vector<bool> chk(N, false);
for(int i = 0; i < N; i++) if(!chk[i]) {
vector<int> V, U; V.eb(B[i]);
for(int j = 0; j < N; j++) if(A[i][j]) {
U.eb(j);
if(1 == A[i][j]) {
if(chk[j]) return 0;
chk[j] = true;
} else {
if(chk[j]) return 0;
chk[j] = true;
V.eb(B[j]);
}
}
sort(allv(V)); univ(V);
if(2 == sz(V)) return 0;
Cy.eb(V); Co.eb(U);
}
vector<vector<int>> D(N, vector<int>(N, 0));
vector<pii> EV;
for(int ci = 0, cn = sz(Cy); ci < cn; ci++) {
auto &cycle = Cy[ci], &comp = Co[ci];
for(int a : comp) for(int b : comp) D[a][b] = 2;
for(int r : cycle) {
vector<int> V;
for(int v : comp) if(r == B[v]) V.eb(v);
for(int v : V) EV.eb(r, v);
for(int a : V) for(int b : V) D[a][b] = 1;
}
int L = sz(cycle);
if(1 < L) {
for(int i = 0, j = 1; i < L; i++, j++) {
if(j == L) j = 0;
EV.eb(cycle[i], cycle[j]);
}
}
}
for(int i = 0; i < N; i++) if(D[i] != A[i]) return 0;
vector<vector<int>> ret(N, vector<int>(N, 0));
for(auto [a, b] : EV) if(a != b) ret[a][b] = ret[b][a] = 1;
build(ret);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
166 ms |
26492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
166 ms |
26492 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
166 ms |
26608 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
79 ms |
8692 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
42 ms |
7284 KB |
Output is correct |
21 |
Correct |
169 ms |
26528 KB |
Output is correct |
22 |
Correct |
173 ms |
26548 KB |
Output is correct |
23 |
Correct |
189 ms |
26488 KB |
Output is correct |
24 |
Correct |
168 ms |
26544 KB |
Output is correct |
25 |
Correct |
89 ms |
12584 KB |
Output is correct |
26 |
Correct |
66 ms |
8664 KB |
Output is correct |
27 |
Correct |
180 ms |
26480 KB |
Output is correct |
28 |
Correct |
211 ms |
26592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
252 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 |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
7 ms |
1364 KB |
Output is correct |
9 |
Correct |
178 ms |
26604 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1364 KB |
Output is correct |
13 |
Correct |
183 ms |
26468 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
700 KB |
Output is correct |
17 |
Correct |
77 ms |
8600 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
44 ms |
7264 KB |
Output is correct |
22 |
Correct |
163 ms |
27888 KB |
Output is correct |
23 |
Correct |
182 ms |
28128 KB |
Output is correct |
24 |
Correct |
180 ms |
27888 KB |
Output is correct |
25 |
Correct |
68 ms |
10152 KB |
Output is correct |
26 |
Correct |
74 ms |
14076 KB |
Output is correct |
27 |
Correct |
167 ms |
27888 KB |
Output is correct |
28 |
Correct |
180 ms |
27964 KB |
Output is correct |
29 |
Correct |
75 ms |
10228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
43 ms |
7256 KB |
Output is correct |
5 |
Correct |
163 ms |
26468 KB |
Output is correct |
6 |
Correct |
183 ms |
26460 KB |
Output is correct |
7 |
Correct |
199 ms |
26500 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
47 ms |
7284 KB |
Output is correct |
10 |
Correct |
162 ms |
27956 KB |
Output is correct |
11 |
Correct |
189 ms |
27908 KB |
Output is correct |
12 |
Correct |
172 ms |
27936 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
43 ms |
7192 KB |
Output is correct |
17 |
Correct |
161 ms |
27876 KB |
Output is correct |
18 |
Correct |
165 ms |
27916 KB |
Output is correct |
19 |
Correct |
165 ms |
27892 KB |
Output is correct |
20 |
Correct |
167 ms |
28044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
166 ms |
26492 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
166 ms |
26608 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
79 ms |
8692 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
42 ms |
7284 KB |
Output is correct |
21 |
Correct |
169 ms |
26528 KB |
Output is correct |
22 |
Correct |
173 ms |
26548 KB |
Output is correct |
23 |
Correct |
189 ms |
26488 KB |
Output is correct |
24 |
Correct |
168 ms |
26544 KB |
Output is correct |
25 |
Correct |
89 ms |
12584 KB |
Output is correct |
26 |
Correct |
66 ms |
8664 KB |
Output is correct |
27 |
Correct |
180 ms |
26480 KB |
Output is correct |
28 |
Correct |
211 ms |
26592 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
252 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 |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
300 KB |
Output is correct |
36 |
Correct |
7 ms |
1364 KB |
Output is correct |
37 |
Correct |
178 ms |
26604 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1364 KB |
Output is correct |
41 |
Correct |
183 ms |
26468 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
700 KB |
Output is correct |
45 |
Correct |
77 ms |
8600 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
44 ms |
7264 KB |
Output is correct |
50 |
Correct |
163 ms |
27888 KB |
Output is correct |
51 |
Correct |
182 ms |
28128 KB |
Output is correct |
52 |
Correct |
180 ms |
27888 KB |
Output is correct |
53 |
Correct |
68 ms |
10152 KB |
Output is correct |
54 |
Correct |
74 ms |
14076 KB |
Output is correct |
55 |
Correct |
167 ms |
27888 KB |
Output is correct |
56 |
Correct |
180 ms |
27964 KB |
Output is correct |
57 |
Correct |
75 ms |
10228 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
696 KB |
Output is correct |
61 |
Correct |
70 ms |
10104 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
45 ms |
7288 KB |
Output is correct |
66 |
Correct |
68 ms |
14136 KB |
Output is correct |
67 |
Correct |
68 ms |
14084 KB |
Output is correct |
68 |
Correct |
70 ms |
14084 KB |
Output is correct |
69 |
Correct |
67 ms |
10100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
166 ms |
26492 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
166 ms |
26608 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
79 ms |
8692 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
42 ms |
7284 KB |
Output is correct |
21 |
Correct |
169 ms |
26528 KB |
Output is correct |
22 |
Correct |
173 ms |
26548 KB |
Output is correct |
23 |
Correct |
189 ms |
26488 KB |
Output is correct |
24 |
Correct |
168 ms |
26544 KB |
Output is correct |
25 |
Correct |
89 ms |
12584 KB |
Output is correct |
26 |
Correct |
66 ms |
8664 KB |
Output is correct |
27 |
Correct |
180 ms |
26480 KB |
Output is correct |
28 |
Correct |
211 ms |
26592 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
252 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 |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
300 KB |
Output is correct |
36 |
Correct |
7 ms |
1364 KB |
Output is correct |
37 |
Correct |
178 ms |
26604 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1364 KB |
Output is correct |
41 |
Correct |
183 ms |
26468 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
700 KB |
Output is correct |
45 |
Correct |
77 ms |
8600 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
44 ms |
7264 KB |
Output is correct |
50 |
Correct |
163 ms |
27888 KB |
Output is correct |
51 |
Correct |
182 ms |
28128 KB |
Output is correct |
52 |
Correct |
180 ms |
27888 KB |
Output is correct |
53 |
Correct |
68 ms |
10152 KB |
Output is correct |
54 |
Correct |
74 ms |
14076 KB |
Output is correct |
55 |
Correct |
167 ms |
27888 KB |
Output is correct |
56 |
Correct |
180 ms |
27964 KB |
Output is correct |
57 |
Correct |
75 ms |
10228 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 |
292 KB |
Output is correct |
61 |
Correct |
43 ms |
7256 KB |
Output is correct |
62 |
Correct |
163 ms |
26468 KB |
Output is correct |
63 |
Correct |
183 ms |
26460 KB |
Output is correct |
64 |
Correct |
199 ms |
26500 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
47 ms |
7284 KB |
Output is correct |
67 |
Correct |
162 ms |
27956 KB |
Output is correct |
68 |
Correct |
189 ms |
27908 KB |
Output is correct |
69 |
Correct |
172 ms |
27936 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
304 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
43 ms |
7192 KB |
Output is correct |
74 |
Correct |
161 ms |
27876 KB |
Output is correct |
75 |
Correct |
165 ms |
27916 KB |
Output is correct |
76 |
Correct |
165 ms |
27892 KB |
Output is correct |
77 |
Correct |
167 ms |
28044 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
3 ms |
696 KB |
Output is correct |
81 |
Correct |
70 ms |
10104 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
45 ms |
7288 KB |
Output is correct |
86 |
Correct |
68 ms |
14136 KB |
Output is correct |
87 |
Correct |
68 ms |
14084 KB |
Output is correct |
88 |
Correct |
70 ms |
14084 KB |
Output is correct |
89 |
Correct |
67 ms |
10100 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
596 KB |
Output is correct |
93 |
Correct |
68 ms |
10116 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 |
300 KB |
Output is correct |
97 |
Correct |
17 ms |
2680 KB |
Output is correct |
98 |
Correct |
72 ms |
10104 KB |
Output is correct |
99 |
Correct |
66 ms |
10104 KB |
Output is correct |
100 |
Correct |
67 ms |
10112 KB |
Output is correct |
101 |
Correct |
64 ms |
10116 KB |
Output is correct |
102 |
Correct |
65 ms |
10032 KB |
Output is correct |
103 |
Correct |
65 ms |
10028 KB |
Output is correct |
104 |
Correct |
72 ms |
10100 KB |
Output is correct |
105 |
Correct |
81 ms |
10112 KB |
Output is correct |