#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
//#include "september.h"
#include <vector>
int n;
vector<int> tree[100005];
vector<pii> graph[100005];
int dp[100005];
void init() {
for (int i = 0; i < n; i++) tree[i].clear(), graph[i].clear();
return;
}
void DFS(int node) {
for (int next: tree[node]) {
DFS(next);
dp[node] = max(dp[node], dp[next]);
}
}
void make_graph(vector<int> &arr) {
for (int i = 0; i < n - 1; i++) graph[i].clear();
for (int i = 0; i < n - 2; i++) graph[i].push_back({i + 1, 1});
for (int i = 1; i < n - 1; i++) graph[i].push_back({i - 1, 0});
vector<int> pos(n + 1);
for (int i = 0; i < arr.size(); i++) pos[arr[i]] = i;
for (int i = 1; i < n; i++) dp[i] = pos[i];
DFS(0);
for (int i = 1; i < n; i++) {
graph[pos[i]].push_back({dp[i], 0});
}
}
void Dijkstra(int start, vector<int> &dist) {
fill(dist.begin(), dist.end(), 1e9);
dist[start] = 1;
priority_queue<pii, vector<pii>, greater<>> pq;
pq.push({1, start});
while (pq.size()) {
pii t = pq.top();
pq.pop();
int now = t.second, v = t.first;
if (dist[now] < v) continue;
for (auto &[next, cost]: graph[now]) {
if (dist[next] > v + cost) {
dist[next] = v + cost;
pq.push({v + cost, next});
}
}
}
}
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
n = N;
init();
for (int i = 1; i < N; i++) tree[F[i]].push_back(i);
vector<int> dist[5];
for (int i = 0; i < M; i++) {
dist[i].resize(N + 5);
make_graph(S[i]);
Dijkstra(0, dist[i]);
}
vector<int> ans(N + 5, 1e9);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N - 1; j++) {
ans[S[i][j]] = min(ans[S[i][j]], dist[i][j]);
}
}
set<int> s;
for (int i = 1; i < N; i++) s.insert(ans[i]);
return s.size();
}
Compilation message
september.cpp: In function 'void make_graph(std::vector<int>&)':
september.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < arr.size(); i++) pos[arr[i]] = i;
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
5168 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5212 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5168 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5224 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5168 KB |
Output is correct |
4 |
Correct |
214 ms |
30896 KB |
Output is correct |
5 |
Correct |
201 ms |
28956 KB |
Output is correct |
6 |
Correct |
222 ms |
30228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
5168 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5212 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
214 ms |
30896 KB |
Output is correct |
19 |
Correct |
201 ms |
28956 KB |
Output is correct |
20 |
Correct |
222 ms |
30228 KB |
Output is correct |
21 |
Correct |
315 ms |
27428 KB |
Output is correct |
22 |
Correct |
322 ms |
27424 KB |
Output is correct |
23 |
Correct |
299 ms |
28168 KB |
Output is correct |
24 |
Correct |
312 ms |
27876 KB |
Output is correct |
25 |
Correct |
321 ms |
27256 KB |
Output is correct |
26 |
Correct |
320 ms |
26936 KB |
Output is correct |
27 |
Correct |
309 ms |
28040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5168 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5224 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |