Submission #526326

# Submission time Handle Problem Language Result Execution time Memory
526326 2022-02-14T10:31:49 Z Koosha_mv File Paths (BOI15_fil) C++14
0 / 100
4 ms 1552 KB
#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=3333,maxs=1e6+99;

int n,m,k,s,a[N],b[N],h[N],ans[N],par[N],cnt[maxs];
vector<int> vec,g[N],Q[N];

void dfs(int u){
	vec.pb(h[u]);
	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];
		//cout<<x<<" -> "<<val<<" "<<k<<" "<<b[x]<<" "<<h[u]<<endl;
		if(val<0) continue ;
		if(val==0){
			ans[x]=1;
			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);
	sort(all(vec));
	f(i,1,m+1){
		int u=a[i],p=vec.size()-1;
		for(;;u=par[u]){
			int val=k-b[i]-(h[a[i]]-h[par[u]])-s;
			//cout<<k<<" "<<b[i]<<" "<<h[a[i]]-h[par[u]]<<" : "<<val<<endl;
			while(p>0 && vec[p]>val){
				p--;
			}
			if(vec[p]==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:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
fil.cpp: In function 'int main()':
fil.cpp:73:7: warning: unused variable 'p' [-Wunused-variable]
   73 |   int p;
      |       ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1552 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -