#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=6060,maxs=1e6+99;
int n,m,k,s,a[N],b[N],h[N],ans[N],par[N],cnt[maxs],mark[maxs];
vector<int> g[N],Q[N];
void dfs(int u){
if(h[u]<maxs){
mark[h[u]]=1;
}
/*for(int v=u;;v=par[v]){
cnt[h[u]-h[par[v]]+s]++;
if(v==0) break;
}*/
for(auto x : Q[u]){
int val=k-b[x]-h[u];
if(val<=0) continue ;
/*for(int j=1;j*j<=val;j++){
if(val%j==0 && cnt[j]){
// ans[x]=1;
}
if(val%j==0 && cnt[val/j]){
// ans[x]=1;
}
}*/
}
for(auto v : g[u]){
if(v==par[v]) continue ;
h[v]+=h[u];
dfs(v);
}
/*
for(int v=u;;v=par[v]){
cnt[h[u]-h[par[v]]+s]--;
if(v==0) break;
}*/
}
main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>m>>k>>s;
s++;
f(i,1,n+1){
cin>>par[i]>>h[i];
g[par[i]].pb(i);
h[i]++;
}
f(i,1,m+1){
int p;
cin>>a[i]>>b[i];
b[i]++;
Q[a[i]].pb(i);
}
dfs(0);
f(i,1,m+1){
int u=a[i];
if(h[a[i]]+b[i]==k) ans[i]=1;
for(;;u=par[u]){
int val=k-b[i]-(h[a[i]]-h[u])-s;
if(mark[val]){
ans[i]=1;
}
if(u==0) break;
}
}
f(i,1,m+1){
if(ans[i]) cout<<"YES\n";
else cout<<"NO\n";
}
}
Compilation message
fil.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
61 | main(){
| ^~~~
fil.cpp: In function 'int main()':
fil.cpp:71:7: warning: unused variable 'p' [-Wunused-variable]
71 | int p;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
5836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |