답안 #1107851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107851 2024-11-02T08:20:10 Z koukirocks File Paths (BOI15_fil) C++17
0 / 100
17 ms 848 KB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;

bool can(int v,int x,vvector<pll> &child,vector<int> &fa,vector<set<ll>> &pre,vector<ll> pval,int n,ll s) {
    if (pval[v]==x) return true;
    for (int i=1;i<=n;i++) {
        if (pre[v].find(x-s-pval[i])!=pre[v].end()) return true;
    }
    int tx=x-pval[v];
    vector<int> fac;
    for (int i=1;i<=sqrt(tx)+eps;i++) {
        if (tx%i==0) {
            fac.push_back(i);
            if (i*i!=tx) {
                fac.push_back(tx/i);
            }
        }
    }
    int now=v;
    while (now!=-1) {
        for (int y:fac) {
            if (pre[now].find(pval[now]-tx/y+s)!=pre[now].end()) return true;
        }
        now=fa[now];
    }
    return false;
}

int main() {
    speed;
    ll n,m,k;
    cin>>n>>m>>k;
    ll s;
    cin>>s;
    s++;
    vvector<pll> child(n+1);
    vector<int> fa(n+1);
    vector<set<ll>> pre(n+1);
    vector<ll> pval(n+1);
    fa[0]=-1;
    pre[0].insert(0);
    pval[0]=0;
    for (int i=1;i<=n;i++) {
        ll p,l;
        cin>>p>>l;
        l++;
        child[p].emplace_back(i,l);
        fa[i]=p;
        pval[i]=pval[p]+l;
        pre[i].insert(pval[i]);
    }
    while (m--) {
        int p,l;
        cin>>p>>l;
        l++;
        bool flag = can(p,k-l,child,fa,pre,pval,n,s);
        if (flag) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -