Submission #146117

#TimeUsernameProblemLanguageResultExecution timeMemory
146117evpipisFile Paths (BOI15_fil)C++11
100 / 100
246 ms74872 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int len = 1e6+5; int n, m, k, s; int cnt[len], sz[len], out[len], pre[len], dep[len], par[len]; vector<int> adj[len], vec, nex[len]; void add(int u, int t){ for (int j = 0; j < nex[u].size(); j++) cnt[nex[u][j]] += t; if (t == 1){ if (u == 0) vec.pb(0); else vec.pb(sz[u]+vec.back()); } else{ vec.pop_back(); } } void fix(int u){ pre[dep[u]]++; int p = u; while (true){ nex[p].pb(dep[u]-dep[p]); if (p == 0) break; p = par[p]; } for (int j = 0; j < adj[u].size(); j++){ int v = adj[u][j]; if (v > n) continue; dep[v] = dep[u]+sz[v]; fix(v); } } void dfs(int u){ if (u > n){ int rem = k-(vec.back()+sz[u]); //printf("file: u = %d, rem = %d\n", u-n, rem); if (rem == 0) out[u-n] = 1; for (int i = 1; i*i <= rem; i++) if (rem%i == 0 && ((i-s >= 0 && cnt[i-s]) || (rem/i-s >= 0 && cnt[rem/i-s]))) out[u-n] = 1; int sum = sz[u]+s; for (int i = (int)vec.size()-1; i >= 0; i--){ if (k-sum >= 0 && pre[k-sum]) out[u-n] = 1; if (i > 0) sum += vec[i]-vec[i-1]; } return; } add(u, 1); for (int j = 0; j < adj[u].size(); j++){ int v = adj[u][j]; dfs(v); } add(u, -1); } int main(){ scanf("%d %d %d %d", &n, &m, &k, &s); s++; for (int i = 1; i <= n; i++){ scanf("%d %d", &par[i], &sz[i]); sz[i]++; adj[par[i]].pb(i); } for (int i = n+1; i <= n+m; i++){ scanf("%d %d", &par[i], &sz[i]); sz[i]++; adj[par[i]].pb(i); } fix(0); dfs(0); for (int i = 1; i <= m; i++){ if (out[i]) printf("YES\n"); else printf("NO\n"); } return 0; } /* 3 1 10 2 0 1 1 1 2 1 0 2 */

Compilation message (stderr)

fil.cpp: In function 'void add(int, int)':
fil.cpp:11:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < nex[u].size(); j++)
                     ~~^~~~~~~~~~~~~~~
fil.cpp: In function 'void fix(int)':
fil.cpp:37:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[u].size(); j++){
                     ~~^~~~~~~~~~~~~~~
fil.cpp: In function 'void dfs(int)':
fil.cpp:70:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[u].size(); j++){
                     ~~^~~~~~~~~~~~~~~
fil.cpp: In function 'int main()':
fil.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &n, &m, &k, &s);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fil.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &par[i], &sz[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fil.cpp:88:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &par[i], &sz[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...