#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
struct dsu {
int n;
vector<int> parent, rank;
dsu(int _n) {
n = _n;
parent.resize(n);
rank.resize(n);
for (int i = 0; i < n; i++) {
parent[i] = i;
rank[i] = 1;
}
}
int get(int x) {
if (parent[x] == x) return x;
return parent[x] = get(parent[x]);
}
bool unite(int x, int y) {
x = get(x), y = get(y);
if (x == y) return false;
if (rank[x] < rank[y]) swap(x, y);
parent[y] = x;
rank[x] += rank[y];
return true;
}
vector<int> all_roots() {
set<int> s;
for (int i = 0; i < n; i++) s.insert(parent[i]);
vector<int> res;
for (auto &x : s) res.push_back(x);
return res;
}
};
void path(vector<vector<int>> &answer, vector<int> nodes) {
if (nodes.size() == 1) return;
for (int i = 1; i < (int)nodes.size(); i++) {
answer[nodes[i - 1]][nodes[i]] = 1;
answer[nodes[i]][nodes[i - 1]] = 1;
}
}
void cycle(vector<vector<int>> &answer, vector<int> nodes) {
if (nodes.size() == 1) return;
path(answer, nodes);
answer[nodes.back()][nodes[0]] = 1;
answer[nodes[0]][nodes.back()] = 1;
}
int construct(vector<std::vector<int>> p) {
int n = p.size();
vector<vector<int>> answer;
answer.resize(n);
for (int i = 0; i < n; i++) {
answer[i].resize(n);
for (int j = 0; j < n; j++) {
answer[i][j] = 0;
}
}
dsu d(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] != p[j][i]) return 0;
if (p[i][j] > 0) d.unite(i, j);
}
}
vector<int> roots = d.all_roots();
int roots_num = (int)roots.size();
unordered_map<int, int> ind;
for (int i = 0; i < roots_num; i++) {
ind[roots[i]] = i;
}
vector<vector<int>> parts(roots_num);
for (int i = 0; i < n; i++) {
parts[ind[d.get(i)]].push_back(i);
}
for (int i = 0; i < roots_num; i++) {
vector<int> &cur = parts[i];
int small_sz = (int)cur.size();
for (int j = 0; j < small_sz; j++) {
for (int k = 0; k < small_sz; k++) {
if (p[cur[j]][cur[k]] == 0) return 0;
}
}
path(answer, cur);
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
256 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
256 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
12 ms |
1280 KB |
Output is correct |
13 |
Correct |
258 ms |
22136 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
118 ms |
12120 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
68 ms |
5756 KB |
Output is correct |
21 |
Correct |
249 ms |
22136 KB |
Output is correct |
22 |
Correct |
252 ms |
22136 KB |
Output is correct |
23 |
Correct |
265 ms |
22136 KB |
Output is correct |
24 |
Correct |
250 ms |
22228 KB |
Output is correct |
25 |
Correct |
115 ms |
12156 KB |
Output is correct |
26 |
Correct |
115 ms |
12152 KB |
Output is correct |
27 |
Correct |
257 ms |
22136 KB |
Output is correct |
28 |
Correct |
248 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
512 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 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 |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
256 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
12 ms |
1280 KB |
Output is correct |
13 |
Correct |
258 ms |
22136 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
118 ms |
12120 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
68 ms |
5756 KB |
Output is correct |
21 |
Correct |
249 ms |
22136 KB |
Output is correct |
22 |
Correct |
252 ms |
22136 KB |
Output is correct |
23 |
Correct |
265 ms |
22136 KB |
Output is correct |
24 |
Correct |
250 ms |
22228 KB |
Output is correct |
25 |
Correct |
115 ms |
12156 KB |
Output is correct |
26 |
Correct |
115 ms |
12152 KB |
Output is correct |
27 |
Correct |
257 ms |
22136 KB |
Output is correct |
28 |
Correct |
248 ms |
22136 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Incorrect |
1 ms |
512 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
256 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
12 ms |
1280 KB |
Output is correct |
13 |
Correct |
258 ms |
22136 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
118 ms |
12120 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
68 ms |
5756 KB |
Output is correct |
21 |
Correct |
249 ms |
22136 KB |
Output is correct |
22 |
Correct |
252 ms |
22136 KB |
Output is correct |
23 |
Correct |
265 ms |
22136 KB |
Output is correct |
24 |
Correct |
250 ms |
22228 KB |
Output is correct |
25 |
Correct |
115 ms |
12156 KB |
Output is correct |
26 |
Correct |
115 ms |
12152 KB |
Output is correct |
27 |
Correct |
257 ms |
22136 KB |
Output is correct |
28 |
Correct |
248 ms |
22136 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Incorrect |
1 ms |
512 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |