Submission #1172117

#TimeUsernameProblemLanguageResultExecution timeMemory
1172117LudisseyFile Paths (BOI15_fil)C++20
100 / 100
128 ms101528 KiB
#include <bits/stdc++.h> #define int long long #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() using namespace std; vector<vector<int>> child; vector<vector<int>> achild; vector<vector<int>> afilechild; vector<int> depth; vector<int> a; vector<int> f; vector<int> parent; vector<int> dv; vector<vector<int>> divs; int n,m,k,s; int in=0; int c=1; void prep(int x, int d){ d+=a[x]; depth[x]=d; for (auto u : child[x]) prep(u,d); } void dfs(int x){ if(x>=n-m) return; for (auto u : child[x]) dfs(u); c++; dv[s]=c; for (int j=0; j<sz(achild[x]); j++) { if(depth[achild[x][j]]-depth[x]+s<=k) dv[depth[achild[x][j]]-depth[x]+s]=c; } for (int _j=0; _j<sz(afilechild[x]); _j++) { for (int j=0; j<sz(divs[afilechild[x][_j]]); j++) { if(dv[divs[afilechild[x][_j]][j]]==c) { f[afilechild[x][_j]]=true; break; } } } } signed main() { cin >> n >> m >> k >> s; n+=m+1; depth.resize(n); dv.resize(k+1,0); divs.resize(n); child.resize(n); achild.resize(n); afilechild.resize(n); f.resize(n); a.resize(n); parent.resize(n); s++; for (int i = 1; i < n; i++) { int p; cin >> p>> a[i]; a[i]++; child[p].push_back(i); parent[i]=p; } a[0]=0; parent[0]=-1; prep(0,0); for (int i = n-m; i < n; i++) { int x=k-depth[i]; if(x<=0) continue; for (int j = 1; j <= sqrt(x); j++) { if(x%j==0){ divs[i].push_back(j); divs[i].push_back(x/j); } } } for (int i = 0; i < n-m; i++){ int u=i; while(u>-1){ achild[u].push_back(i); u=parent[u]; } } for (int i = n-m; i < n; i++){ int u=parent[i]; while(u>-1){ afilechild[u].push_back(i); u=parent[u]; } } dfs(0); c++; for (int i = 0; i < n-m; i++) { if(depth[i]+s>k) continue; dv[depth[i]+s]=c; } for (int i = n-m; i < n; i++){ int u=parent[i]; if(depth[i]==k||(k-depth[i])%s==0) f[i]=true; while(u>-1){ int x=depth[i]-depth[u]; int v=k-x; if(v>=0&&dv[v]==c) f[i]=true; u=parent[u]; } } for (int i = n-m; i < n; i++) { if(f[i]) cout << "YES\n"; else cout << "NO\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...