답안 #526409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526409 2022-02-14T17:02:59 Z Koosha_mv File Paths (BOI15_fil) C++14
0 / 100
4 ms 2088 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=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];
		//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);
	f(i,1,m+1){
		int u=a[i];
		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:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main(){
      | ^~~~
fil.cpp: In function 'int main()':
fil.cpp:75:7: warning: unused variable 'p' [-Wunused-variable]
   75 |   int p;
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 2088 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -