Submission #1160440

#TimeUsernameProblemLanguageResultExecution timeMemory
1160440kiwimsySeptember (APIO24_september)C++20
45 / 100
177 ms17852 KiB
#include "september.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> ch; vector<vector<vector<int>>> d; vector<int> p, ind, h; vector<bool> vis, passed; queue<int> q; void dfs(int node){ vis[node] = true; for(int i : ch[node]){ if(!vis[i]) dfs(i); } q.push(node); } void getheight(int node){ vis[node] = true; for(int i : ch[node]){ if(!vis[i]){ h[i] = h[node] + 1; getheight(i); } } } int solve(int N, int M, vector<int> F, vector<vector<int>> S) { ch.clear(), ch.resize(N); h.clear(), h.resize(N); d.clear(), d.resize(M); p.clear(), p.resize(M); ind.clear(), ind.resize(M); int k, maxk = 0, ans = 0; for(int i = 1; i < N; ++i){ ch[F[i]].push_back(i); } vis.assign(N, false); h[0] = 0; getheight(0); for(int i = 0; i < M; ++i){ k = 0; d[i].resize(N); vis.assign(N, false); passed.assign(N, false); for(int j = 0; j < N-1; ++j){ passed[S[i][j]] = true; if(!vis[S[i][j]]) dfs(S[i][j]); while(!q.empty() && passed[q.front()]){ d[i][k].push_back(q.front()); q.pop(); } if(q.empty()) k++; } maxk = max(k, maxk); } for(int i = 0; i < maxk; ++i){ for(int j = 0; j < M; ++j){ for(int l : d[j][i]){ p[j] += h[l]; ind[j]++; } } bool s = true; int tmp = p[0], tmi = ind[0]; for(int j = 1; j < M; ++j){ if(tmp != p[j] || tmi != ind[j]) s = false; } if(s) ans++; } return ans; }
#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...