#include "supertrees.h"
#include <vector>
#include <map>
#include <iostream>
using namespace std;
struct DSU {
int n;
vector<int> link, size;
DSU(int sz) {
n = sz;
link.resize(sz);
size.resize(sz);
for (int i = 0; i < n; i++) {
link[i] = i;
size[i] = 1;
}
}
int find(int x) {
while (x != link[x])
x = link[x];
return x;
}
bool same(int a, int b) {
return find(a) == find(b);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (size[a] < size[b])
swap(a, b);
link[b] = a;
size[a] += size[b];
}
};
int construct(std::vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n));
vector<vector<int>> components(n);
DSU d(n+1);
for (int i = 0; i < n; i++) {
components[i].push_back(i);
for (int j = 0; j < n; j++) {
if (i == j)
continue;
if (p[i][j]) {
if (!d.same(i, j)) {
d.unite(i, j);
components[d.find(i)].push_back(j);
}
}
}
}
// for (int i = 0; i < n; i++) {
// cout << i << ' ';
// for (auto x : components[i])
// cout << x << ' ';
// cout << '\n';
// }
for (int i = 0; i < n; i++) {
if (components[i].size() == 1)
continue;
for (int j = 0; j < (int)components[i].size(); j++) {
for (int k = j+1; k < (int)components[i].size(); k++) {
if (!p[components[i][j]][components[i][k]])
return 0;
}
}
for (int j = 0; j < (int)components[i].size()-1; j++) {
answer[components[i][j]][components[i][j+1]] = 1;
answer[components[i][j+1]][components[i][j]] = 1;
}
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
24188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
24188 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
432 KB |
Output is correct |
12 |
Correct |
6 ms |
1220 KB |
Output is correct |
13 |
Correct |
112 ms |
24064 KB |
Output is correct |
14 |
Correct |
0 ms |
440 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
86 ms |
14196 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
28 ms |
6236 KB |
Output is correct |
21 |
Correct |
118 ms |
23984 KB |
Output is correct |
22 |
Correct |
111 ms |
24144 KB |
Output is correct |
23 |
Correct |
117 ms |
24148 KB |
Output is correct |
24 |
Correct |
109 ms |
24196 KB |
Output is correct |
25 |
Correct |
51 ms |
14164 KB |
Output is correct |
26 |
Correct |
70 ms |
14076 KB |
Output is correct |
27 |
Correct |
117 ms |
24008 KB |
Output is correct |
28 |
Correct |
111 ms |
23984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
428 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
24188 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
432 KB |
Output is correct |
12 |
Correct |
6 ms |
1220 KB |
Output is correct |
13 |
Correct |
112 ms |
24064 KB |
Output is correct |
14 |
Correct |
0 ms |
440 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
86 ms |
14196 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
28 ms |
6236 KB |
Output is correct |
21 |
Correct |
118 ms |
23984 KB |
Output is correct |
22 |
Correct |
111 ms |
24144 KB |
Output is correct |
23 |
Correct |
117 ms |
24148 KB |
Output is correct |
24 |
Correct |
109 ms |
24196 KB |
Output is correct |
25 |
Correct |
51 ms |
14164 KB |
Output is correct |
26 |
Correct |
70 ms |
14076 KB |
Output is correct |
27 |
Correct |
117 ms |
24008 KB |
Output is correct |
28 |
Correct |
111 ms |
23984 KB |
Output is correct |
29 |
Correct |
0 ms |
344 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 |
428 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
24188 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
432 KB |
Output is correct |
12 |
Correct |
6 ms |
1220 KB |
Output is correct |
13 |
Correct |
112 ms |
24064 KB |
Output is correct |
14 |
Correct |
0 ms |
440 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
86 ms |
14196 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
28 ms |
6236 KB |
Output is correct |
21 |
Correct |
118 ms |
23984 KB |
Output is correct |
22 |
Correct |
111 ms |
24144 KB |
Output is correct |
23 |
Correct |
117 ms |
24148 KB |
Output is correct |
24 |
Correct |
109 ms |
24196 KB |
Output is correct |
25 |
Correct |
51 ms |
14164 KB |
Output is correct |
26 |
Correct |
70 ms |
14076 KB |
Output is correct |
27 |
Correct |
117 ms |
24008 KB |
Output is correct |
28 |
Correct |
111 ms |
23984 KB |
Output is correct |
29 |
Correct |
0 ms |
344 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 |
428 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |