제출 #992579

#제출 시각아이디문제언어결과실행 시간메모리
992579KasymK9월 (APIO24_september)C++17
100 / 100
106 ms12936 KiB
#include "bits/stdc++.h" using namespace std; const int N = 1e5+5; vector<int> adj[N]; int pos[N], vis[N], r; void dfs(int nd){ if(vis[nd]) return; vis[nd] = 1; r = max(r, pos[nd]); for(auto i : adj[nd]) dfs(i); } int solve(int n, int m, vector<int> F, vector<vector<int>> S){ // assert(m == 1); for(int i = 0; i <= n; ++i) adj[i].clear(), pos[i] = 0, vis[i] = 0; for(int i = 1; i < n; ++i) adj[F[i]].push_back(i); for(int i = 0; i < n-1; ++i) for(int k = 0; k < m; ++k) pos[S[k][i]] = max(pos[S[k][i]], i); int l = 0, answer = 0; r = 0; while(r < n-1){ while(l <= r){ for(int k = 0; k < m; ++k) dfs(S[k][l]); l++; } r++, answer++; } return answer; }
#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...