#include <bits/stdc++.h>
#include "supertrees.h"
using ll = long long;
using namespace std;
const int N = 1010;
int dsu[N];
int get(int x) {
return dsu[x] == x ? x : dsu[x] = get(dsu[x]);
}
void merge(int x, int y) {
dsu[get(x)] = get(y);
}
int construct(vector<vector<int>> p) {
int n = (int)p.size();
for (int i = 0; i < n; i++) {
dsu[i] = i;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 1) {
merge(i, j);
}
}
}
vector<vector<int>> b(n, vector<int>(n, 0)), group(n), group2(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] != 1 && get(i) == get(j)) {
return 0;
}
}
group[get(i)].push_back(i);
}
vector<int> g;
for (int i = 0; i < n; i++) {
for (int j = 1; j < group[i].size(); j++) {
b[group[i][j - 1]][group[i][j]] = 1;
b[group[i][j]][group[i][j - 1]] = 1;
}
if (!group[i].empty()) {
g.push_back(i);
}
}
for (int i : g) {
for (int j : g) {
if (p[i][j] == 2 && i < j) {
merge(i, j);
}
}
}
for (int i : g) {
for (int j : g) {
if (i != j && get(i) == get(j)) {
for (int ii : group[i]) {
if (p[ii][j] != 2) {
return 0;
}
}
}
}
group2[get(i)].push_back(i);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < group2[i].size() && group2[i].size() > 1; j++) {
b[group2[i][(j - 1 + group2[i].size()) % group2[i].size()]][group2[i][j]] = 1;
b[group2[i][j]][group2[i][(j - 1 + group2[i].size()) % group2[i].size()]] = 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 3) {
return 0;
}
}
}
build(b);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j = 1; j < group[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int j = 0; j < group2[i].size() && group2[i].size() > 1; j++) {
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
9 ms |
1112 KB |
Output is correct |
7 |
Correct |
148 ms |
22120 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 |
9 ms |
1112 KB |
Output is correct |
7 |
Correct |
148 ms |
22120 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
152 ms |
22356 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
73 ms |
12308 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
5784 KB |
Output is correct |
21 |
Correct |
149 ms |
22032 KB |
Output is correct |
22 |
Correct |
146 ms |
22100 KB |
Output is correct |
23 |
Correct |
163 ms |
22300 KB |
Output is correct |
24 |
Correct |
148 ms |
22132 KB |
Output is correct |
25 |
Correct |
60 ms |
12116 KB |
Output is correct |
26 |
Correct |
60 ms |
12312 KB |
Output is correct |
27 |
Correct |
151 ms |
22064 KB |
Output is correct |
28 |
Correct |
145 ms |
22300 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
38 ms |
5868 KB |
Output is correct |
5 |
Correct |
145 ms |
22100 KB |
Output is correct |
6 |
Correct |
144 ms |
22096 KB |
Output is correct |
7 |
Correct |
149 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
38 ms |
5920 KB |
Output is correct |
10 |
Correct |
154 ms |
22044 KB |
Output is correct |
11 |
Correct |
149 ms |
22188 KB |
Output is correct |
12 |
Correct |
158 ms |
22288 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
37 ms |
5716 KB |
Output is correct |
17 |
Correct |
157 ms |
22120 KB |
Output is correct |
18 |
Correct |
148 ms |
22104 KB |
Output is correct |
19 |
Correct |
148 ms |
22228 KB |
Output is correct |
20 |
Correct |
146 ms |
22284 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 |
9 ms |
1112 KB |
Output is correct |
7 |
Correct |
148 ms |
22120 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
152 ms |
22356 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
73 ms |
12308 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
5784 KB |
Output is correct |
21 |
Correct |
149 ms |
22032 KB |
Output is correct |
22 |
Correct |
146 ms |
22100 KB |
Output is correct |
23 |
Correct |
163 ms |
22300 KB |
Output is correct |
24 |
Correct |
148 ms |
22132 KB |
Output is correct |
25 |
Correct |
60 ms |
12116 KB |
Output is correct |
26 |
Correct |
60 ms |
12312 KB |
Output is correct |
27 |
Correct |
151 ms |
22064 KB |
Output is correct |
28 |
Correct |
145 ms |
22300 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
9 ms |
1112 KB |
Output is correct |
7 |
Correct |
148 ms |
22120 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
152 ms |
22356 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
73 ms |
12308 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
5784 KB |
Output is correct |
21 |
Correct |
149 ms |
22032 KB |
Output is correct |
22 |
Correct |
146 ms |
22100 KB |
Output is correct |
23 |
Correct |
163 ms |
22300 KB |
Output is correct |
24 |
Correct |
148 ms |
22132 KB |
Output is correct |
25 |
Correct |
60 ms |
12116 KB |
Output is correct |
26 |
Correct |
60 ms |
12312 KB |
Output is correct |
27 |
Correct |
151 ms |
22064 KB |
Output is correct |
28 |
Correct |
145 ms |
22300 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |