Submission #953145

# Submission time Handle Problem Language Result Execution time Memory
953145 2024-03-25T14:42:40 Z PM1 File Paths (BOI15_fil) C++17
33 / 100
29 ms 3160 KB
#include <bits/stdc++.h>
using namespace std;
const int mxn=3e3+5,mxs=1e6+5;
int n,m,s,k,par[mxn*2],dis[mxn*2];
bitset<mxs>b[mxn*2];
vector<int>all,v[mxn];
bool mark[mxs],ans[mxn*2];
void make(int x,bool y){
	int z=x;
	while(x!=0){
		x=par[x];
		int d=dis[z]-dis[x];
		if(d<=k)mark[d]=y;
	}
}
void dfs(int z){
	int y=par[z];
	
	for(auto i:v[z]){
		dfs(i);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>k>>s;
	s++;
	for(int i=1;i<=n+m;i++){
		int x,y;
		cin>>x>>y;
		par[i]=x;
		dis[i]=dis[x]+y+1;
		if(i<=n){
			all.push_back(dis[i]);
			v[x].push_back(i);
		}
	}
	all.push_back(0);
	for(int i=n+1;i<=n+m;i++){
		make(i,1);
		if(dis[i]==k)ans[i]=1;
		for(auto j:all){
			int res=k-j-s;
			if(res>=0 && mark[res])ans[i]=1;
		}
		make(i,0);
	}
	dfs(0);
	
	for(int i=n+1;i<=n+m;i++){
		if(ans[i])
			cout<<"YES"<<'\n';
		else
			cout<<"NO"<<'\n';
	}
	return 0;
}

Compilation message

fil.cpp: In function 'void dfs(int)':
fil.cpp:17:6: warning: unused variable 'y' [-Wunused-variable]
   17 |  int y=par[z];
      |      ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2652 KB Output is correct
2 Correct 12 ms 2652 KB Output is correct
3 Correct 12 ms 2652 KB Output is correct
4 Correct 13 ms 2652 KB Output is correct
5 Correct 29 ms 2892 KB Output is correct
6 Correct 29 ms 2892 KB Output is correct
7 Correct 22 ms 3160 KB Output is correct
8 Correct 21 ms 2844 KB Output is correct
9 Correct 13 ms 2648 KB Output is correct
10 Correct 11 ms 2652 KB Output is correct
11 Correct 10 ms 2652 KB Output is correct
12 Correct 27 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -