Submission #941395

# Submission time Handle Problem Language Result Execution time Memory
941395 2024-03-08T17:37:29 Z Darren0724 Hacker (BOI15_hac) C++17
0 / 100
217 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=6005;
const int M=1000005;
const int INF=1e9;
int n,m,l,p;
vector<int> v(N),adj[N],ans(N),t(M,0),t1(M,0);
void dfs(int k,int pa){
    for(int j:adj[k]){
        if(j==pa)continue;
        v[j]+=v[k];
        dfs(j,k);
    }
}
vector<int> h,h1;
vector<int> rec[N];
void dfs1(int k,int pa){
    for(int j:h){
        if(l-(v[k]-j)>=0&&t[l-(v[k]-j)]==1){
            ans[k]=1;
        }
    }
    h.push_back(v[k]);
    for(int j:adj[k]){
        if(j==pa)continue;
        dfs1(j,k);
    }
    h.pop_back();
}
void dfs2(int k,int rt){
    if(k<=n)rec[rt].push_back(v[k]-v[rt]+p);
    for(int j:adj[k]){
        dfs2(j,rt);
    }
}
void dfs3(int k,int pa){
    for(int j:rec[k]){
        t1[j]++;
    }
    int tmp=l-v[k];
    for(int i=1;i*i<=tmp;i++){
        if(tmp%i==0){
            int a=tmp/i;
            if(t1[i]||t1[a]){
                ans[k]=1;
            }
        }
    }
    for(int j:adj[k]){
        if(j==pa)continue;
        dfs3(j,k);
    }
    for(int j:rec[k]){
        t1[j]--;
    }
}
int32_t main() {
    LCBorz;
    cin>>n>>m>>l>>p;
    p++;
    for(int i=1;i<=n+m;i++){
        int a,b;cin>>a>>b;
        v[i]=b+1;
        adj[a].push_back(i);
    }
    dfs(0,0);
    for(int i=0;i<=n;i++){
        if(v[i]+p<M&&v[i]+p>=0)t[v[i]+p]=1;
    }
    for(int i=n+1;i<=n+m;i++){
        ans[i]|=(v[i]==l);
    }
    dfs1(0,0);
    for(int i=0;i<=n+m;i++){
        dfs2(i,i);
    }
    dfs3(0,0);
    for(int i=n+1;i<=n+m;i++){
        cout<<(ans[i]?"YES":"NO")<<endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 217 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 217 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 187 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 217 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -