Submission #32326

#TimeUsernameProblemLanguageResultExecution timeMemory
32326dqhungdlFile Paths (BOI15_fil)C++14
33 / 100
156 ms2144 KiB
#include <bits/stdc++.h> using namespace std; int n,m,k,s,Count=0,l[3005],P[3005],sum[3005],In[3005],Ou[3005]; vector<int> g[3005]; void DFS(int u,int len) { In[u]=++Count; sum[u]=len; for(int i=0;i<g[u].size();i++) DFS(g[u][i],len+l[g[u][i]]); Ou[u]=Count; } bool Father(int u,int v) { return (In[u]<=In[v]&&In[v]<=Ou[u]); } bool Check(int p,int len) { int S=len,tmp=p; while(tmp>0) { S+=l[tmp]; tmp=P[tmp]; } for(int i=0;i<=n;i++) if(Father(i,p)==true) for(int j=0;j<=n;j++) { if(S+(sum[j]-sum[i]+s)==k) return true; if(Father(i,j)==true&&(k-S)%(sum[j]-sum[i]+s)==0) return true; } return false; } void Sub1() { DFS(0,0); int p,len; for(int i=1;i<=m;i++) { cin>>p>>len; if(Check(p,len+1)==true) cout<<"YES\n"; else cout<<"NO\n"; } } int main() { //freopen("FIL.INP","r",stdin); //freopen("FIL.OUT","w",stdout); scanf("%d%d%d%d",&n,&m,&k,&s); s++; for(int i=1;i<=n;i++) { scanf("%d%d",&P[i],&l[i]); l[i]++; g[P[i]].push_back(i); } if(n<=500&&m<=500) Sub1(); }

Compilation message (stderr)

fil.cpp: In function 'void DFS(int, int)':
fil.cpp:11:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g[u].size();i++)
                  ^
fil.cpp: In function 'int main()':
fil.cpp:59:34: 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:63:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&P[i],&l[i]);
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...