Submission #992578

#TimeUsernameProblemLanguageResultExecution timeMemory
992578KasymKSeptember (APIO24_september)C++17
45 / 100
105 ms11836 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) pos[S[0][i]] = i; int l = 0, answer = 0; r = 0; while(r < n-1){ while(l <= r){ dfs(S[0][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...