This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define L(node) node * 2
#define R(node) node * 2 + 1
#define N 1000005
#define int long long
int sum[N], done[N];
int len[N], par[N], file[N], len2[N], path[N];
vector<int> child[N];
void dfs(int node, int d)
{
d += len[node];
path[node] = d;
done[d] = 1;
for (auto i : child[node])
dfs(i, d);
}
int32_t main()
{
fastio();
int n, m, k;
cin>>n>>m>>k;
int s;
cin>>s;
s++;
len[0] = 1;
for (int i = 1; i <= n; i++)
{
cin>>par[i]>>len[i];
len[i]++;
child[par[i]].pb(i);
}
for (int i = 1; i <= m; i++)
cin>>file[i]>>len2[i];
dfs(0, 0);
for (int i = 0; i <= n; i++)
assert(path[i] <= k);
for (int i = 1; i <= m; i++)
{
int sum = len2[i];
int flag = 0;
if (sum + path[file[i]] == k) flag = 1;
int curr = file[i];
while(curr != 0)
{
if (k >= sum + s && done[k - sum - s]) flag = 1;
sum += len[curr];
curr = par[curr];
}
sum++;
if (flag) cout<<"YES\n";
else cout<<"NO\n";
}
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |