#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define N 100005
#define pb push_back
vector<int> vec[N];
int construct(vector<vector<int>> p){
int n = p.size();
vector<vector<int>> b(n, vector<int>(n, 0));
vector<int> vis(n, 0), ok(n, 0);
int cnt = 0;
for (int i = 0; i < n; i++){
if (vis[i]){
if (p[i] != vec[vis[i]]) return 0;
continue;
}
cnt++;
for (int j = 0; j < n; j++){
if (p[i][j] == 3) return 0;
if (p[i][j] and i != j){
if (p[i][j] == 1){
b[i][j] = b[j][i] = 1;
vis[j] = cnt;
}
}
vec[cnt].pb(p[i][j]);
}
}
for (int i = 0; i < n; i++){
if (vis[i] or ok[i]) continue;
deque<int> v;
ok[i] = 1;
for (int j = 0; j < n; j++){
if (p[i][j] == 2 and !vis[j]){
ok[j] = 1;
v.pb(j);
}
}
if (!v.size()) continue;
if (v.size() == 1) return 0;
v.push_front(i);
for (int j = 0; j < (int)v.size(); j++){
for (int k = j+1; k < (int)v.size(); k++) if (p[v[j]][v[k]] != 2) return 0;
for (int k = 0; k < n; k++){
if (p[v[j]][k] == 2 and !ok[k] and !vis[k]) return 0;
}
}
b[v[0]][v.back()] = b[v.back()][v[0]] = 1;
for (int j = 1; j < (int)v.size(); j++){
b[v[j-1]][v[j]] = b[v[j]][v[j-1]] = 1;
}
}
// for (int i = 0; i < n; i++){
// for (int j = 0; j < n; j++) cout << b[i][j] << ' ';
// cout << '\n';
// }
build(b);
return 1;
}
// int main ()
// {
// 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];
// }
// int x = construct(p);
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
3500 KB |
Output is correct |
7 |
Correct |
177 ms |
24300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
3500 KB |
Output is correct |
7 |
Correct |
177 ms |
24300 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
7 ms |
3668 KB |
Output is correct |
13 |
Correct |
152 ms |
28336 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
3064 KB |
Output is correct |
17 |
Correct |
73 ms |
14412 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
39 ms |
8224 KB |
Output is correct |
21 |
Correct |
174 ms |
24396 KB |
Output is correct |
22 |
Correct |
148 ms |
25908 KB |
Output is correct |
23 |
Correct |
162 ms |
24368 KB |
Output is correct |
24 |
Correct |
155 ms |
28228 KB |
Output is correct |
25 |
Correct |
74 ms |
14528 KB |
Output is correct |
26 |
Correct |
60 ms |
15564 KB |
Output is correct |
27 |
Correct |
160 ms |
24464 KB |
Output is correct |
28 |
Correct |
154 ms |
28216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
7 ms |
3668 KB |
Output is correct |
9 |
Correct |
153 ms |
28404 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
8 ms |
3668 KB |
Output is correct |
13 |
Correct |
165 ms |
28348 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
3320 KB |
Output is correct |
17 |
Correct |
77 ms |
18484 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
45 ms |
9132 KB |
Output is correct |
22 |
Correct |
175 ms |
28364 KB |
Output is correct |
23 |
Correct |
152 ms |
28440 KB |
Output is correct |
24 |
Correct |
200 ms |
28340 KB |
Output is correct |
25 |
Correct |
64 ms |
18484 KB |
Output is correct |
26 |
Correct |
66 ms |
18496 KB |
Output is correct |
27 |
Correct |
151 ms |
28336 KB |
Output is correct |
28 |
Correct |
185 ms |
28320 KB |
Output is correct |
29 |
Correct |
64 ms |
18484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
37 ms |
8228 KB |
Output is correct |
5 |
Correct |
149 ms |
24372 KB |
Output is correct |
6 |
Correct |
150 ms |
25932 KB |
Output is correct |
7 |
Correct |
161 ms |
24424 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
46 ms |
9012 KB |
Output is correct |
10 |
Correct |
153 ms |
28340 KB |
Output is correct |
11 |
Correct |
157 ms |
28488 KB |
Output is correct |
12 |
Correct |
165 ms |
28348 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
45 ms |
9004 KB |
Output is correct |
17 |
Correct |
154 ms |
28364 KB |
Output is correct |
18 |
Correct |
152 ms |
26548 KB |
Output is correct |
19 |
Correct |
158 ms |
26812 KB |
Output is correct |
20 |
Correct |
152 ms |
28364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
3500 KB |
Output is correct |
7 |
Correct |
177 ms |
24300 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
7 ms |
3668 KB |
Output is correct |
13 |
Correct |
152 ms |
28336 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
3064 KB |
Output is correct |
17 |
Correct |
73 ms |
14412 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
39 ms |
8224 KB |
Output is correct |
21 |
Correct |
174 ms |
24396 KB |
Output is correct |
22 |
Correct |
148 ms |
25908 KB |
Output is correct |
23 |
Correct |
162 ms |
24368 KB |
Output is correct |
24 |
Correct |
155 ms |
28228 KB |
Output is correct |
25 |
Correct |
74 ms |
14528 KB |
Output is correct |
26 |
Correct |
60 ms |
15564 KB |
Output is correct |
27 |
Correct |
160 ms |
24464 KB |
Output is correct |
28 |
Correct |
154 ms |
28216 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2644 KB |
Output is correct |
32 |
Correct |
1 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
7 ms |
3668 KB |
Output is correct |
37 |
Correct |
153 ms |
28404 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
1 ms |
2644 KB |
Output is correct |
40 |
Correct |
8 ms |
3668 KB |
Output is correct |
41 |
Correct |
165 ms |
28348 KB |
Output is correct |
42 |
Correct |
2 ms |
2644 KB |
Output is correct |
43 |
Correct |
1 ms |
2644 KB |
Output is correct |
44 |
Correct |
4 ms |
3320 KB |
Output is correct |
45 |
Correct |
77 ms |
18484 KB |
Output is correct |
46 |
Correct |
1 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
1 ms |
2644 KB |
Output is correct |
49 |
Correct |
45 ms |
9132 KB |
Output is correct |
50 |
Correct |
175 ms |
28364 KB |
Output is correct |
51 |
Correct |
152 ms |
28440 KB |
Output is correct |
52 |
Correct |
200 ms |
28340 KB |
Output is correct |
53 |
Correct |
64 ms |
18484 KB |
Output is correct |
54 |
Correct |
66 ms |
18496 KB |
Output is correct |
55 |
Correct |
151 ms |
28336 KB |
Output is correct |
56 |
Correct |
185 ms |
28320 KB |
Output is correct |
57 |
Correct |
64 ms |
18484 KB |
Output is correct |
58 |
Correct |
1 ms |
2644 KB |
Output is correct |
59 |
Correct |
1 ms |
2644 KB |
Output is correct |
60 |
Correct |
4 ms |
3132 KB |
Output is correct |
61 |
Correct |
88 ms |
14400 KB |
Output is correct |
62 |
Correct |
1 ms |
2644 KB |
Output is correct |
63 |
Correct |
1 ms |
2644 KB |
Output is correct |
64 |
Correct |
1 ms |
2644 KB |
Output is correct |
65 |
Correct |
38 ms |
8896 KB |
Output is correct |
66 |
Correct |
65 ms |
16824 KB |
Output is correct |
67 |
Correct |
65 ms |
16316 KB |
Output is correct |
68 |
Correct |
61 ms |
15680 KB |
Output is correct |
69 |
Correct |
83 ms |
18368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
3500 KB |
Output is correct |
7 |
Correct |
177 ms |
24300 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
7 ms |
3668 KB |
Output is correct |
13 |
Correct |
152 ms |
28336 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
3064 KB |
Output is correct |
17 |
Correct |
73 ms |
14412 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
39 ms |
8224 KB |
Output is correct |
21 |
Correct |
174 ms |
24396 KB |
Output is correct |
22 |
Correct |
148 ms |
25908 KB |
Output is correct |
23 |
Correct |
162 ms |
24368 KB |
Output is correct |
24 |
Correct |
155 ms |
28228 KB |
Output is correct |
25 |
Correct |
74 ms |
14528 KB |
Output is correct |
26 |
Correct |
60 ms |
15564 KB |
Output is correct |
27 |
Correct |
160 ms |
24464 KB |
Output is correct |
28 |
Correct |
154 ms |
28216 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2644 KB |
Output is correct |
32 |
Correct |
1 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
7 ms |
3668 KB |
Output is correct |
37 |
Correct |
153 ms |
28404 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
1 ms |
2644 KB |
Output is correct |
40 |
Correct |
8 ms |
3668 KB |
Output is correct |
41 |
Correct |
165 ms |
28348 KB |
Output is correct |
42 |
Correct |
2 ms |
2644 KB |
Output is correct |
43 |
Correct |
1 ms |
2644 KB |
Output is correct |
44 |
Correct |
4 ms |
3320 KB |
Output is correct |
45 |
Correct |
77 ms |
18484 KB |
Output is correct |
46 |
Correct |
1 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
1 ms |
2644 KB |
Output is correct |
49 |
Correct |
45 ms |
9132 KB |
Output is correct |
50 |
Correct |
175 ms |
28364 KB |
Output is correct |
51 |
Correct |
152 ms |
28440 KB |
Output is correct |
52 |
Correct |
200 ms |
28340 KB |
Output is correct |
53 |
Correct |
64 ms |
18484 KB |
Output is correct |
54 |
Correct |
66 ms |
18496 KB |
Output is correct |
55 |
Correct |
151 ms |
28336 KB |
Output is correct |
56 |
Correct |
185 ms |
28320 KB |
Output is correct |
57 |
Correct |
64 ms |
18484 KB |
Output is correct |
58 |
Correct |
1 ms |
2644 KB |
Output is correct |
59 |
Correct |
1 ms |
2644 KB |
Output is correct |
60 |
Correct |
1 ms |
2644 KB |
Output is correct |
61 |
Correct |
37 ms |
8228 KB |
Output is correct |
62 |
Correct |
149 ms |
24372 KB |
Output is correct |
63 |
Correct |
150 ms |
25932 KB |
Output is correct |
64 |
Correct |
161 ms |
24424 KB |
Output is correct |
65 |
Correct |
1 ms |
2644 KB |
Output is correct |
66 |
Correct |
46 ms |
9012 KB |
Output is correct |
67 |
Correct |
153 ms |
28340 KB |
Output is correct |
68 |
Correct |
157 ms |
28488 KB |
Output is correct |
69 |
Correct |
165 ms |
28348 KB |
Output is correct |
70 |
Correct |
1 ms |
2644 KB |
Output is correct |
71 |
Correct |
1 ms |
2644 KB |
Output is correct |
72 |
Correct |
1 ms |
2644 KB |
Output is correct |
73 |
Correct |
45 ms |
9004 KB |
Output is correct |
74 |
Correct |
154 ms |
28364 KB |
Output is correct |
75 |
Correct |
152 ms |
26548 KB |
Output is correct |
76 |
Correct |
158 ms |
26812 KB |
Output is correct |
77 |
Correct |
152 ms |
28364 KB |
Output is correct |
78 |
Correct |
1 ms |
2644 KB |
Output is correct |
79 |
Correct |
1 ms |
2644 KB |
Output is correct |
80 |
Correct |
4 ms |
3132 KB |
Output is correct |
81 |
Correct |
88 ms |
14400 KB |
Output is correct |
82 |
Correct |
1 ms |
2644 KB |
Output is correct |
83 |
Correct |
1 ms |
2644 KB |
Output is correct |
84 |
Correct |
1 ms |
2644 KB |
Output is correct |
85 |
Correct |
38 ms |
8896 KB |
Output is correct |
86 |
Correct |
65 ms |
16824 KB |
Output is correct |
87 |
Correct |
65 ms |
16316 KB |
Output is correct |
88 |
Correct |
61 ms |
15680 KB |
Output is correct |
89 |
Correct |
83 ms |
18368 KB |
Output is correct |
90 |
Correct |
1 ms |
2644 KB |
Output is correct |
91 |
Correct |
1 ms |
2644 KB |
Output is correct |
92 |
Correct |
4 ms |
3028 KB |
Output is correct |
93 |
Correct |
76 ms |
14388 KB |
Output is correct |
94 |
Correct |
1 ms |
2644 KB |
Output is correct |
95 |
Correct |
1 ms |
2644 KB |
Output is correct |
96 |
Correct |
1 ms |
2644 KB |
Output is correct |
97 |
Correct |
17 ms |
6184 KB |
Output is correct |
98 |
Correct |
63 ms |
16596 KB |
Output is correct |
99 |
Correct |
64 ms |
16932 KB |
Output is correct |
100 |
Correct |
75 ms |
16676 KB |
Output is correct |
101 |
Correct |
62 ms |
17700 KB |
Output is correct |
102 |
Correct |
75 ms |
16332 KB |
Output is correct |
103 |
Correct |
74 ms |
16348 KB |
Output is correct |
104 |
Correct |
74 ms |
16416 KB |
Output is correct |
105 |
Correct |
77 ms |
16416 KB |
Output is correct |