제출 #1035320

#제출 시각아이디문제언어결과실행 시간메모리
1035320LaviniaTornaghi9월 (APIO24_september)C++17
0 / 100
1 ms348 KiB
#include "september.h" #include <bits/stdc++.h> using namespace std; int solve(int N, int M, vector<int> F, vector<vector<int>> S) { assert(M == 1); vector<vector<int>> adj(N); for (int i = 1; i < N; i++) adj[F[i]].push_back(i); vector<vector<int>> inv_S(M, vector<int>(N)); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { inv_S[i][S[i][j]] = j; } } vector<bool> visited(N); auto dfs = [&](auto &&dfs, int node) -> int { if (visited[node]) return -1; visited[node] = true; int ans = inv_S[0][node]; for (auto x: adj[node]) ans = max(ans, dfs(dfs, x)); return ans; }; int curr_l = 0, k = 0; while (curr_l != N) { k++; int curr_r = curr_l + 1; for (; curr_l < curr_r; curr_l++) { curr_r = max(curr_r, dfs(dfs, curr_l)); } } return k; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...