#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 1e3+5;
int T, vis[N][N], cur[N], tp[N];
set<int> A[N], B[N];
int F1(int n, int i, vector<vector<int>> p, vector<vector<int>>&b){
if (A[cur[i]].find(i) != A[cur[i]].end()) return p[tp[i]] == p[i];
for (int j = 0; j < n; j++){
if (i == j) continue;
if (vis[cur[i]][j] != (p[i][j] == 0)) return 0;
if (p[i][j] == 1){
tp[j] = i;
A[cur[i]].insert(j);
B[cur[i]].erase(j);
b[i][j] = b[j][i] = 1;
}
}
return 1;
}
void F2(int n, int i, vector<vector<int>> p, vector<vector<int>>&b){
++T;
B[T].insert(i);
for (int j = 0; j < n; j++){
if (i == j) continue;
if (p[i][j] == 0) vis[T][j] = 1;
else{
cur[j] = T;
if (p[i][j] == 1){
tp[j] = i;
A[T].insert(j);
b[i][j] = b[j][i] = 1;
}else B[T].insert(j);
}
}
}
// void build(vector<vector<int>> p){
// int n = p.size();
// for (int i = 0; i < n; i++){
// for (int j = 0; j < n; j++) cout << p[i][j] << " ";
// cout << '\n';
// }
// }
int construct(vector<vector<int>> p){
int n = p.size();
vector<vector<int>> b(n, vector<int>(n, 0));
for (int i = 0; i < n; i++){
if (count(all(p[i]), 3)) return 0;
if (cur[i]){
if (!F1(n, i, p, b)) return 0;
}else F2(n, i, p, b);
}
for (int i = 1; i <= T; i++){
if (B[i].size() <= 1) continue;
if (B[i].size() == 2) return 0;
int lst = *B[i].rbegin();
for (auto j : B[i]){
b[lst][j] = b[j][lst] = 1;
lst = j;
}
}
build(b);
return 1;
}
// int main ()
// {
// ios::sync_with_stdio(false);
// cin.tie(0);
// int n;
// cin >> n;
// vector<vector<int>> p(n, vector<int>(n));
// for (int i = 0; i < n; i++){
// for (int j = 0; j < n; j++) cin >> p[i][j];
// }
// cout << construct(p);
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
349 ms |
22316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
349 ms |
22316 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
2060 KB |
Output is correct |
13 |
Correct |
357 ms |
26028 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
980 KB |
Output is correct |
17 |
Correct |
68 ms |
16244 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
70 ms |
6128 KB |
Output is correct |
21 |
Correct |
340 ms |
22416 KB |
Output is correct |
22 |
Correct |
352 ms |
23824 KB |
Output is correct |
23 |
Correct |
347 ms |
22148 KB |
Output is correct |
24 |
Correct |
332 ms |
25888 KB |
Output is correct |
25 |
Correct |
212 ms |
16204 KB |
Output is correct |
26 |
Correct |
146 ms |
17296 KB |
Output is correct |
27 |
Correct |
340 ms |
22140 KB |
Output is correct |
28 |
Correct |
377 ms |
25852 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
396 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
9 ms |
2116 KB |
Output is correct |
9 |
Correct |
343 ms |
27204 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1308 KB |
Output is correct |
13 |
Correct |
335 ms |
23280 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1044 KB |
Output is correct |
17 |
Correct |
70 ms |
17460 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 |
69 ms |
6572 KB |
Output is correct |
22 |
Correct |
340 ms |
23384 KB |
Output is correct |
23 |
Correct |
335 ms |
24044 KB |
Output is correct |
24 |
Correct |
364 ms |
23256 KB |
Output is correct |
25 |
Correct |
255 ms |
21116 KB |
Output is correct |
26 |
Correct |
75 ms |
17356 KB |
Output is correct |
27 |
Correct |
346 ms |
24108 KB |
Output is correct |
28 |
Correct |
346 ms |
23296 KB |
Output is correct |
29 |
Correct |
293 ms |
21024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
72 ms |
6072 KB |
Output is correct |
5 |
Correct |
336 ms |
22244 KB |
Output is correct |
6 |
Correct |
329 ms |
23736 KB |
Output is correct |
7 |
Correct |
343 ms |
22116 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
70 ms |
6120 KB |
Output is correct |
10 |
Correct |
373 ms |
22260 KB |
Output is correct |
11 |
Correct |
347 ms |
22920 KB |
Output is correct |
12 |
Correct |
371 ms |
22188 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
78 ms |
6160 KB |
Output is correct |
17 |
Correct |
345 ms |
22248 KB |
Output is correct |
18 |
Correct |
339 ms |
22236 KB |
Output is correct |
19 |
Correct |
372 ms |
22264 KB |
Output is correct |
20 |
Correct |
343 ms |
25916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
349 ms |
22316 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
2060 KB |
Output is correct |
13 |
Correct |
357 ms |
26028 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
980 KB |
Output is correct |
17 |
Correct |
68 ms |
16244 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
70 ms |
6128 KB |
Output is correct |
21 |
Correct |
340 ms |
22416 KB |
Output is correct |
22 |
Correct |
352 ms |
23824 KB |
Output is correct |
23 |
Correct |
347 ms |
22148 KB |
Output is correct |
24 |
Correct |
332 ms |
25888 KB |
Output is correct |
25 |
Correct |
212 ms |
16204 KB |
Output is correct |
26 |
Correct |
146 ms |
17296 KB |
Output is correct |
27 |
Correct |
340 ms |
22140 KB |
Output is correct |
28 |
Correct |
377 ms |
25852 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
396 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
9 ms |
2116 KB |
Output is correct |
37 |
Correct |
343 ms |
27204 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1308 KB |
Output is correct |
41 |
Correct |
335 ms |
23280 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
1044 KB |
Output is correct |
45 |
Correct |
70 ms |
17460 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 |
69 ms |
6572 KB |
Output is correct |
50 |
Correct |
340 ms |
23384 KB |
Output is correct |
51 |
Correct |
335 ms |
24044 KB |
Output is correct |
52 |
Correct |
364 ms |
23256 KB |
Output is correct |
53 |
Correct |
255 ms |
21116 KB |
Output is correct |
54 |
Correct |
75 ms |
17356 KB |
Output is correct |
55 |
Correct |
346 ms |
24108 KB |
Output is correct |
56 |
Correct |
346 ms |
23296 KB |
Output is correct |
57 |
Correct |
293 ms |
21024 KB |
Output is correct |
58 |
Correct |
1 ms |
380 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
3 ms |
1108 KB |
Output is correct |
61 |
Correct |
70 ms |
17328 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 |
72 ms |
6632 KB |
Output is correct |
66 |
Correct |
75 ms |
18136 KB |
Output is correct |
67 |
Correct |
72 ms |
18116 KB |
Output is correct |
68 |
Correct |
137 ms |
18240 KB |
Output is correct |
69 |
Correct |
246 ms |
21880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
349 ms |
22316 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
2060 KB |
Output is correct |
13 |
Correct |
357 ms |
26028 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
980 KB |
Output is correct |
17 |
Correct |
68 ms |
16244 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
70 ms |
6128 KB |
Output is correct |
21 |
Correct |
340 ms |
22416 KB |
Output is correct |
22 |
Correct |
352 ms |
23824 KB |
Output is correct |
23 |
Correct |
347 ms |
22148 KB |
Output is correct |
24 |
Correct |
332 ms |
25888 KB |
Output is correct |
25 |
Correct |
212 ms |
16204 KB |
Output is correct |
26 |
Correct |
146 ms |
17296 KB |
Output is correct |
27 |
Correct |
340 ms |
22140 KB |
Output is correct |
28 |
Correct |
377 ms |
25852 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
396 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
9 ms |
2116 KB |
Output is correct |
37 |
Correct |
343 ms |
27204 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1308 KB |
Output is correct |
41 |
Correct |
335 ms |
23280 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
1044 KB |
Output is correct |
45 |
Correct |
70 ms |
17460 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 |
69 ms |
6572 KB |
Output is correct |
50 |
Correct |
340 ms |
23384 KB |
Output is correct |
51 |
Correct |
335 ms |
24044 KB |
Output is correct |
52 |
Correct |
364 ms |
23256 KB |
Output is correct |
53 |
Correct |
255 ms |
21116 KB |
Output is correct |
54 |
Correct |
75 ms |
17356 KB |
Output is correct |
55 |
Correct |
346 ms |
24108 KB |
Output is correct |
56 |
Correct |
346 ms |
23296 KB |
Output is correct |
57 |
Correct |
293 ms |
21024 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
72 ms |
6072 KB |
Output is correct |
62 |
Correct |
336 ms |
22244 KB |
Output is correct |
63 |
Correct |
329 ms |
23736 KB |
Output is correct |
64 |
Correct |
343 ms |
22116 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
70 ms |
6120 KB |
Output is correct |
67 |
Correct |
373 ms |
22260 KB |
Output is correct |
68 |
Correct |
347 ms |
22920 KB |
Output is correct |
69 |
Correct |
371 ms |
22188 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
78 ms |
6160 KB |
Output is correct |
74 |
Correct |
345 ms |
22248 KB |
Output is correct |
75 |
Correct |
339 ms |
22236 KB |
Output is correct |
76 |
Correct |
372 ms |
22264 KB |
Output is correct |
77 |
Correct |
343 ms |
25916 KB |
Output is correct |
78 |
Correct |
1 ms |
380 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
3 ms |
1108 KB |
Output is correct |
81 |
Correct |
70 ms |
17328 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 |
72 ms |
6632 KB |
Output is correct |
86 |
Correct |
75 ms |
18136 KB |
Output is correct |
87 |
Correct |
72 ms |
18116 KB |
Output is correct |
88 |
Correct |
137 ms |
18240 KB |
Output is correct |
89 |
Correct |
246 ms |
21880 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
340 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
66 ms |
14160 KB |
Output is correct |
94 |
Correct |
0 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 |
19 ms |
4952 KB |
Output is correct |
98 |
Correct |
76 ms |
18216 KB |
Output is correct |
99 |
Correct |
99 ms |
18220 KB |
Output is correct |
100 |
Correct |
100 ms |
18244 KB |
Output is correct |
101 |
Correct |
132 ms |
19356 KB |
Output is correct |
102 |
Correct |
65 ms |
14144 KB |
Output is correct |
103 |
Correct |
65 ms |
14152 KB |
Output is correct |
104 |
Correct |
63 ms |
14152 KB |
Output is correct |
105 |
Correct |
74 ms |
14068 KB |
Output is correct |