# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32326 | 2017-10-09T03:17:21 Z | dqhungdl | File Paths (BOI15_fil) | C++14 | 156 ms | 2144 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2144 KB | Output is correct |
2 | Correct | 0 ms | 2144 KB | Output is correct |
3 | Correct | 9 ms | 2144 KB | Output is correct |
4 | Correct | 79 ms | 2144 KB | Output is correct |
5 | Correct | 29 ms | 2144 KB | Output is correct |
6 | Correct | 6 ms | 2144 KB | Output is correct |
7 | Correct | 156 ms | 2144 KB | Output is correct |
8 | Correct | 3 ms | 2144 KB | Output is correct |
9 | Correct | 6 ms | 2144 KB | Output is correct |
10 | Correct | 0 ms | 2144 KB | Output is correct |
11 | Correct | 3 ms | 2144 KB | Output is correct |
12 | Correct | 49 ms | 2144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2144 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2144 KB | Output is correct |
2 | Correct | 0 ms | 2144 KB | Output is correct |
3 | Correct | 9 ms | 2144 KB | Output is correct |
4 | Correct | 79 ms | 2144 KB | Output is correct |
5 | Correct | 29 ms | 2144 KB | Output is correct |
6 | Correct | 6 ms | 2144 KB | Output is correct |
7 | Correct | 156 ms | 2144 KB | Output is correct |
8 | Correct | 3 ms | 2144 KB | Output is correct |
9 | Correct | 6 ms | 2144 KB | Output is correct |
10 | Correct | 0 ms | 2144 KB | Output is correct |
11 | Correct | 3 ms | 2144 KB | Output is correct |
12 | Correct | 49 ms | 2144 KB | Output is correct |
13 | Incorrect | 0 ms | 2144 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |