#include "september.h"
#include <bits/stdc++.h>
using namespace std;
int solve(int n, int m, vector<int> par, vector<vector<int>> s) {
vector<int> p(n);
iota(p.begin(), p.end(), 0);
vector<int> from(n, n), to(n, 0);
function<int(int)> GetPar = [&](int x) {
return p[x] == x ? x : p[x] = GetPar(p[x]);
};
auto Merge = [&](int x, int y) {
x = GetPar(x);
y = GetPar(y);
if (x == y) {
return;
}
from[x] = min(from[x], from[y]);
to[x] = max(to[x], to[y]);
p[y] = x;
};
for (int i = 0; i < m; i++) {
for (int j = 0; j + 1 < n; j++) {
from[s[i][j]] = min(from[s[i][j]], j);
to[s[i][j]] = max(to[s[i][j]], j);
}
}
vector<vector<int>> g(n);
for (int i = 1; i < n; i++) {
g[par[i]].push_back(i);
}
int T = 0;
vector<int> dfn(n);
vector<int> dfo(n);
function<void(int)> Dfs = [&](int v) {
dfn[v] = ++T;
for (int u : g[v]) {
Dfs(u);
}
dfo[v] = ++T;
};
Dfs(0);
auto IsAnc = [&](int x, int y) {
return dfn[x] <= dfn[y] && dfo[y] <= dfo[x];
};
for (int k = 0; k < m; k++) {
vector<int> pos(n);
for (int i = 0; i + 1 < n; i++) {
pos[s[k][i]] = i;
}
pos[0] = n;
auto up = pos;
function<void(int)> Dfs = [&](int v) {
for (int u : g[v]) {
up[u] = min(up[u], up[v]);
Dfs(u);
}
};
Dfs(0);
vector<int> mx(n);
iota(mx.begin(), mx.end(), 0);
for (int i = 1; i < n; i++) {
mx[up[i]] = max(mx[up[i]], pos[i]);
}
for (int i = 0; i + 1 < n; i++) {
if (i > 0) {
mx[i] = max(mx[i], mx[i - 1]);
}
if (mx[i] > i) {
Merge(s[k][i], s[k][i + 1]);
}
}
}
vector<pair<int, int>> ev;
for (int i = 1; i < n; i++) {
if (GetPar(i) != i) {
continue;
}
ev.emplace_back(from[i], ~to[i]);
ev.emplace_back(to[i], to[i]);
}
sort(ev.begin(), ev.end());
multiset<int> st;
int res = 0;
for (auto& p : ev) {
if (st.empty()) {
res += 1;
}
int v = p.second;
if (v < 0) {
st.insert(~v);
} else {
st.erase(st.find(v));
}
}
return res;
}
Compilation message
september.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<std::vector<int> >)':
september.cpp:44:8: warning: variable 'IsAnc' set but not used [-Wunused-but-set-variable]
44 | auto IsAnc = [&](int x, int y) {
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
404 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
404 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
184 ms |
21244 KB |
Output is correct |
5 |
Correct |
182 ms |
20864 KB |
Output is correct |
6 |
Correct |
185 ms |
20924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
404 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
184 ms |
21244 KB |
Output is correct |
19 |
Correct |
182 ms |
20864 KB |
Output is correct |
20 |
Correct |
185 ms |
20924 KB |
Output is correct |
21 |
Correct |
279 ms |
14000 KB |
Output is correct |
22 |
Correct |
280 ms |
13912 KB |
Output is correct |
23 |
Correct |
273 ms |
15588 KB |
Output is correct |
24 |
Correct |
253 ms |
16456 KB |
Output is correct |
25 |
Correct |
282 ms |
14320 KB |
Output is correct |
26 |
Correct |
275 ms |
14020 KB |
Output is correct |
27 |
Correct |
249 ms |
13328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
184 ms |
21244 KB |
Output is correct |
8 |
Correct |
182 ms |
20864 KB |
Output is correct |
9 |
Correct |
185 ms |
20924 KB |
Output is correct |
10 |
Correct |
92 ms |
21416 KB |
Output is correct |
11 |
Correct |
84 ms |
22740 KB |
Output is correct |
12 |
Correct |
89 ms |
22288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
404 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
184 ms |
21244 KB |
Output is correct |
36 |
Correct |
182 ms |
20864 KB |
Output is correct |
37 |
Correct |
185 ms |
20924 KB |
Output is correct |
38 |
Correct |
279 ms |
14000 KB |
Output is correct |
39 |
Correct |
280 ms |
13912 KB |
Output is correct |
40 |
Correct |
273 ms |
15588 KB |
Output is correct |
41 |
Correct |
253 ms |
16456 KB |
Output is correct |
42 |
Correct |
282 ms |
14320 KB |
Output is correct |
43 |
Correct |
275 ms |
14020 KB |
Output is correct |
44 |
Correct |
249 ms |
13328 KB |
Output is correct |
45 |
Correct |
92 ms |
21416 KB |
Output is correct |
46 |
Correct |
84 ms |
22740 KB |
Output is correct |
47 |
Correct |
89 ms |
22288 KB |
Output is correct |
48 |
Correct |
105 ms |
16160 KB |
Output is correct |
49 |
Correct |
109 ms |
16276 KB |
Output is correct |
50 |
Correct |
98 ms |
16464 KB |
Output is correct |
51 |
Correct |
118 ms |
17148 KB |
Output is correct |
52 |
Correct |
112 ms |
15140 KB |
Output is correct |
53 |
Correct |
106 ms |
15204 KB |
Output is correct |
54 |
Correct |
99 ms |
16968 KB |
Output is correct |