#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 15;
int sz[N][M], p[N][M];
vector<int> g[N];
void make_set(int v, int t) {
p[v][t] = v;
sz[v][t] = 1;
}
int find_set(int v, int t) {
if (p[v][t] == v) return v;
return p[v][t] = find_set(p[v][t], t);
}
void merge(int a, int b, int t) {
a = find_set(a, t);
b = find_set(b, t);
if (a == b) return;
if (sz[a][t] < sz[b][t]) swap(a, b);
sz[a][t] += sz[b][t];
p[b][t] = a;
}
void add_edges(int v, int t) {
for (auto u : g[v]) {
if (p[u][t] >= 0) {
merge(u, v, t);
}
}
}
int solve(int n, int m, vector<int> F, vector<vector<int>> S) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
p[i][j] = -1;
}
g[i].clear();
}
for (int i = 1; i < n; i++) {
g[i].push_back(F[i]);
g[F[i]].push_back(i);
}
int ans = 0;
for (int i = 0; i < m; i++) {
make_set(0, i);
}
set<int> myset[M];
for (int i = n - 2; i >= 0; i--) {
bool check = true;
for (int j = 0; j < m; j++) {
int x = S[j][i];
myset[j].insert(x);
make_set(x, j);
add_edges(x, j);
if (sz[find_set(x, j)][j] != n - i) {
check = false;
}
}
if (n <= 1000) {
for (int j = 1; j < m; j++) {
if (myset[j] != myset[j - 1]) {
check = false;
}
}
}
if (check) {
ans++;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6744 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
1 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6744 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
7000 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
4 |
Correct |
15 ms |
7000 KB |
Output is correct |
5 |
Correct |
15 ms |
7052 KB |
Output is correct |
6 |
Correct |
15 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6744 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
1 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6744 KB |
Output is correct |
18 |
Correct |
1 ms |
6748 KB |
Output is correct |
19 |
Correct |
1 ms |
7000 KB |
Output is correct |
20 |
Correct |
1 ms |
6748 KB |
Output is correct |
21 |
Correct |
1 ms |
6748 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
1 ms |
6748 KB |
Output is correct |
25 |
Correct |
15 ms |
7000 KB |
Output is correct |
26 |
Correct |
15 ms |
7052 KB |
Output is correct |
27 |
Correct |
15 ms |
7004 KB |
Output is correct |
28 |
Correct |
14 ms |
7000 KB |
Output is correct |
29 |
Correct |
15 ms |
7072 KB |
Output is correct |
30 |
Correct |
14 ms |
7000 KB |
Output is correct |
31 |
Correct |
12 ms |
7060 KB |
Output is correct |
32 |
Correct |
14 ms |
7068 KB |
Output is correct |
33 |
Correct |
15 ms |
7096 KB |
Output is correct |
34 |
Correct |
15 ms |
7056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
4 |
Correct |
190 ms |
26696 KB |
Output is correct |
5 |
Correct |
191 ms |
26372 KB |
Output is correct |
6 |
Correct |
225 ms |
26540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6744 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
7000 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6748 KB |
Output is correct |
18 |
Correct |
190 ms |
26696 KB |
Output is correct |
19 |
Correct |
191 ms |
26372 KB |
Output is correct |
20 |
Correct |
225 ms |
26540 KB |
Output is correct |
21 |
Correct |
293 ms |
27880 KB |
Output is correct |
22 |
Correct |
289 ms |
26800 KB |
Output is correct |
23 |
Correct |
261 ms |
27744 KB |
Output is correct |
24 |
Correct |
283 ms |
27868 KB |
Output is correct |
25 |
Correct |
289 ms |
28076 KB |
Output is correct |
26 |
Correct |
288 ms |
27876 KB |
Output is correct |
27 |
Correct |
268 ms |
24976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
4 |
Correct |
15 ms |
7000 KB |
Output is correct |
5 |
Correct |
15 ms |
7052 KB |
Output is correct |
6 |
Correct |
15 ms |
7004 KB |
Output is correct |
7 |
Correct |
190 ms |
26696 KB |
Output is correct |
8 |
Correct |
191 ms |
26372 KB |
Output is correct |
9 |
Correct |
225 ms |
26540 KB |
Output is correct |
10 |
Correct |
312 ms |
46164 KB |
Output is correct |
11 |
Correct |
311 ms |
46420 KB |
Output is correct |
12 |
Correct |
311 ms |
47188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6744 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
1 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6744 KB |
Output is correct |
18 |
Correct |
1 ms |
6748 KB |
Output is correct |
19 |
Correct |
1 ms |
7000 KB |
Output is correct |
20 |
Correct |
1 ms |
6748 KB |
Output is correct |
21 |
Correct |
1 ms |
6748 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
1 ms |
6748 KB |
Output is correct |
25 |
Correct |
15 ms |
7000 KB |
Output is correct |
26 |
Correct |
15 ms |
7052 KB |
Output is correct |
27 |
Correct |
15 ms |
7004 KB |
Output is correct |
28 |
Correct |
14 ms |
7000 KB |
Output is correct |
29 |
Correct |
15 ms |
7072 KB |
Output is correct |
30 |
Correct |
14 ms |
7000 KB |
Output is correct |
31 |
Correct |
12 ms |
7060 KB |
Output is correct |
32 |
Correct |
14 ms |
7068 KB |
Output is correct |
33 |
Correct |
15 ms |
7096 KB |
Output is correct |
34 |
Correct |
15 ms |
7056 KB |
Output is correct |
35 |
Correct |
190 ms |
26696 KB |
Output is correct |
36 |
Correct |
191 ms |
26372 KB |
Output is correct |
37 |
Correct |
225 ms |
26540 KB |
Output is correct |
38 |
Correct |
293 ms |
27880 KB |
Output is correct |
39 |
Correct |
289 ms |
26800 KB |
Output is correct |
40 |
Correct |
261 ms |
27744 KB |
Output is correct |
41 |
Correct |
283 ms |
27868 KB |
Output is correct |
42 |
Correct |
289 ms |
28076 KB |
Output is correct |
43 |
Correct |
288 ms |
27876 KB |
Output is correct |
44 |
Correct |
268 ms |
24976 KB |
Output is correct |
45 |
Correct |
312 ms |
46164 KB |
Output is correct |
46 |
Correct |
311 ms |
46420 KB |
Output is correct |
47 |
Correct |
311 ms |
47188 KB |
Output is correct |
48 |
Incorrect |
425 ms |
47756 KB |
Output isn't correct |
49 |
Halted |
0 ms |
0 KB |
- |