# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32326 | dqhungdl | File Paths (BOI15_fil) | C++14 | 156 ms | 2144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |