# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
32326 | dqhungdl | File Paths (BOI15_fil) | C++14 | 156 ms | 2144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
컴파일 시 표준 에러 (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... |