# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32325 | dqhungdl | File Paths (BOI15_fil) | C++14 | 0 ms | 2060 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,p[6005],l[6005];
vector<int> V;
void Check(int u)
{
V.clear();
int sum=0;
while(u>0)
{
V.push_back(l[u]);
sum+=l[u];
u=p[u];
}
reverse(V.begin(),V.end());
V.pop_back();
if(sum==k)
{
printf("YES\n");
return;
}
if(sum>k)
{
printf("NO\n");
return;
}
if((k-sum)%s==0)
{
printf("YES\n");
return;
}
for(int i=0;i<V.size();i++)
{
int sum1=s;
for(int j=i;j<V.size();j++)
{
sum1+=V[j];
if((k-sum)%sum1==0)
{
printf("YES\n");
return;
}
}
}
printf("NO\n");
}
void Sub2()
{
for(int i=n+1;i<=n+m;i++)
Check(i);
}
int main()
{
//freopen("FIL.INP","r",stdin);
scanf("%d%d%d%d",&n,&m,&k,&s);
s++;
for(int i=1;i<=n+m;i++)
{
scanf("%d%d",&p[i],&l[i]);
l[i]++;
}
if(n<=3000&&m<=3000)
Sub2();
}
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... |