#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
const int mx = 3e3, mx2 = 1e7;
vi adj[mx+1], files[mx+1];
int cost[mx+1], costf[mx+1], ans[mx+1], s, k, cnt[mx2+1];
void dfs2 (int u, int cur, int d) {
cnt[cur] += d;
for (int v : adj[u]) dfs2 (v, cur+cost[v], d);
}
void dfs (int u, int cur) {
dfs2 (u, 0, 1);
for (int v : adj[u]) dfs (v, cur + cost[v]);
for (int v : files[u]) {
int x = k - cur - costf[v];
if (x==0) ans[v] = 1;
for (int i = 1; i*i <= x; ++i) {
if (x%i==0) {
if (i-s>=0 && cnt[i-s]) ans[v] = 1;
if (x/i-s>=0 && cnt[x/i-s]) ans[v] = 1;
}
}
}
dfs2 (u, 0, -1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m >> k >> s;
++s;
rep (i,1,n) {
int p; cin >> p >> cost[i];
++cost[i];
adj[p].pb(i);
}
rep (i,1,m) {
int p; cin >> p >> costf[i];
++costf[i];
files[p].pb(i);
}
dfs (0,0);
rep (i,1,m) cout << (ans[i]?"YES":"NO") << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
4460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |