#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
int n, vis[1005], used[1005], co = 0;
void dfs(int i) {
if (vis[i] > 0) {
return;
}
vis[i] = co;
for (int j = 0; j < n; j++) {
if (i == j || adj[i][j] == 0) {
continue;
}
dfs(j);
}
}
int construct(vector<vector<int>> p) {
n = p.size();
adj = p;
vector<vector<int>> ans(n, vector<int>(n, 0));
for (int i = 0; i < n; i++) {
if (vis[i] > 0) {
continue;
}
co++;
dfs(i);
}
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) {
if (vis[i] == vis[j]) {
return 0;
}
} else {
if (vis[i] != vis[j]) {
return 0;
}
}
}
}
for (int i = 1; i <= co; i++) {
vector<int> root;
for (int j = 0; j < n; j++) {
if (vis[j] == i && !used[j]) {
root.push_back(j);
used[j] = 1;
for (int k = 0; k < n; k++) {
if (k == j) {
continue;
}
if (p[j][k] == 1) {
used[k] = 1;
ans[j][k] = 1;
ans[k][j] = 1;
}
}
}
}
if (root.size() == 1) {
continue;
}
if (root.size() < 3) {
return 0;
}
for (int j = 1; j < n; j++) {
ans[root[j]][root[j-1]] = 1;
ans[root[j-1]][root[j]] = 1;
}
ans[root.front()][root.back()] = 1;
ans[root.back()][root.front()] = 1;
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
118 ms |
26132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
118 ms |
26132 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
115 ms |
26140 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
948 KB |
Output is correct |
17 |
Correct |
60 ms |
16056 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
6900 KB |
Output is correct |
21 |
Correct |
121 ms |
25936 KB |
Output is correct |
22 |
Correct |
122 ms |
25936 KB |
Output is correct |
23 |
Correct |
121 ms |
26140 KB |
Output is correct |
24 |
Correct |
113 ms |
25936 KB |
Output is correct |
25 |
Correct |
52 ms |
16212 KB |
Output is correct |
26 |
Correct |
48 ms |
16140 KB |
Output is correct |
27 |
Correct |
120 ms |
26156 KB |
Output is correct |
28 |
Correct |
115 ms |
25936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
1372 KB |
Output is correct |
9 |
Correct |
120 ms |
27728 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
115 ms |
27940 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
62 ms |
18100 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
440 KB |
Output is correct |
21 |
Runtime error |
17 ms |
9048 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
39 ms |
6908 KB |
Output is correct |
5 |
Correct |
115 ms |
25936 KB |
Output is correct |
6 |
Correct |
127 ms |
25936 KB |
Output is correct |
7 |
Correct |
121 ms |
26140 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Runtime error |
15 ms |
8516 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
118 ms |
26132 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
115 ms |
26140 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
948 KB |
Output is correct |
17 |
Correct |
60 ms |
16056 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
6900 KB |
Output is correct |
21 |
Correct |
121 ms |
25936 KB |
Output is correct |
22 |
Correct |
122 ms |
25936 KB |
Output is correct |
23 |
Correct |
121 ms |
26140 KB |
Output is correct |
24 |
Correct |
113 ms |
25936 KB |
Output is correct |
25 |
Correct |
52 ms |
16212 KB |
Output is correct |
26 |
Correct |
48 ms |
16140 KB |
Output is correct |
27 |
Correct |
120 ms |
26156 KB |
Output is correct |
28 |
Correct |
115 ms |
25936 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
120 ms |
27728 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
6 ms |
1372 KB |
Output is correct |
41 |
Correct |
115 ms |
27940 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
62 ms |
18100 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
440 KB |
Output is correct |
49 |
Runtime error |
17 ms |
9048 KB |
Execution killed with signal 11 |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
118 ms |
26132 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
115 ms |
26140 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
948 KB |
Output is correct |
17 |
Correct |
60 ms |
16056 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
6900 KB |
Output is correct |
21 |
Correct |
121 ms |
25936 KB |
Output is correct |
22 |
Correct |
122 ms |
25936 KB |
Output is correct |
23 |
Correct |
121 ms |
26140 KB |
Output is correct |
24 |
Correct |
113 ms |
25936 KB |
Output is correct |
25 |
Correct |
52 ms |
16212 KB |
Output is correct |
26 |
Correct |
48 ms |
16140 KB |
Output is correct |
27 |
Correct |
120 ms |
26156 KB |
Output is correct |
28 |
Correct |
115 ms |
25936 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
120 ms |
27728 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
6 ms |
1372 KB |
Output is correct |
41 |
Correct |
115 ms |
27940 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
62 ms |
18100 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
440 KB |
Output is correct |
49 |
Runtime error |
17 ms |
9048 KB |
Execution killed with signal 11 |
50 |
Halted |
0 ms |
0 KB |
- |