#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
int f[MAXN], sz[MAXN], L[MAXN], f2[MAXN];
vector<vector<int>> answer;
inline void add(int i, int j) {
answer[i][j] = answer[j][i] = 1;
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n, 0);
answer.push_back(row);
}
vector<int> roots;
for (int i = 0; i < n; i++) {
f[i] = i;
int lst = i;
for (int j = 0; j < i; j++)
if (p[i][j] == 1)
lst = j;
if (lst != i) add(lst, i), f[i] = f[lst];
else roots.push_back(i);
}
int m = roots.size();
for (int i = 0; i < m; i++) {
f2[i] = i;
int lst = i;
for (int j = 0; j < i; j++)
if (p[roots[i]][roots[j]] == 2)
lst = j;
if (lst != i) {
add(roots[i], roots[lst]);
f2[i] = f2[lst];
L[f2[i]] = i;
} else L[i] = i;
}
for (int i = 0; i < m; i++) {
if (L[i] && L[i] != i) {
add(roots[i], roots[L[i]]);
}
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
153 ms |
21960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
153 ms |
21960 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1212 KB |
Output is correct |
13 |
Correct |
161 ms |
23944 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
39 ms |
6260 KB |
Output is correct |
5 |
Correct |
179 ms |
23972 KB |
Output is correct |
6 |
Correct |
169 ms |
23928 KB |
Output is correct |
7 |
Correct |
164 ms |
23952 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
41 ms |
6188 KB |
Output is correct |
10 |
Correct |
167 ms |
23928 KB |
Output is correct |
11 |
Correct |
153 ms |
23992 KB |
Output is correct |
12 |
Correct |
171 ms |
23932 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
14 |
Correct |
0 ms |
304 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
40 ms |
6184 KB |
Output is correct |
17 |
Correct |
160 ms |
23992 KB |
Output is correct |
18 |
Correct |
159 ms |
23972 KB |
Output is correct |
19 |
Correct |
156 ms |
24080 KB |
Output is correct |
20 |
Correct |
156 ms |
23948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
153 ms |
21960 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1212 KB |
Output is correct |
13 |
Correct |
161 ms |
23944 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
153 ms |
21960 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1212 KB |
Output is correct |
13 |
Correct |
161 ms |
23944 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |