# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
526411 |
2022-02-14T17:16:28 Z |
Koosha_mv |
File Paths (BOI15_fil) |
C++14 |
|
1000 ms |
47720 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];
vector<int> g[N],Q[N];
map<int,int> mark;
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:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main(){
| ^~~~
fil.cpp: In function 'int main()':
fil.cpp:72:7: warning: unused variable 'p' [-Wunused-variable]
72 | int p;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1356 KB |
Output is correct |
2 |
Correct |
4 ms |
1384 KB |
Output is correct |
3 |
Correct |
4 ms |
1488 KB |
Output is correct |
4 |
Correct |
4 ms |
1488 KB |
Output is correct |
5 |
Execution timed out |
1014 ms |
47720 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |