# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146117 | evpipis | File Paths (BOI15_fil) | C++11 | 246 ms | 74872 KiB |
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 pb push_back
const int len = 1e6+5;
int n, m, k, s;
int cnt[len], sz[len], out[len], pre[len], dep[len], par[len];
vector<int> adj[len], vec, nex[len];
void add(int u, int t){
for (int j = 0; j < nex[u].size(); j++)
cnt[nex[u][j]] += t;
if (t == 1){
if (u == 0)
vec.pb(0);
else
vec.pb(sz[u]+vec.back());
}
else{
vec.pop_back();
}
}
void fix(int u){
pre[dep[u]]++;
int p = u;
while (true){
nex[p].pb(dep[u]-dep[p]);
if (p == 0)
break;
p = par[p];
}
for (int j = 0; j < adj[u].size(); j++){
int v = adj[u][j];
if (v > n) continue;
dep[v] = dep[u]+sz[v];
fix(v);
}
}
void dfs(int u){
if (u > n){
int rem = k-(vec.back()+sz[u]);
//printf("file: u = %d, rem = %d\n", u-n, rem);
if (rem == 0)
out[u-n] = 1;
for (int i = 1; i*i <= rem; i++)
if (rem%i == 0 && ((i-s >= 0 && cnt[i-s]) || (rem/i-s >= 0 && cnt[rem/i-s])))
out[u-n] = 1;
int sum = sz[u]+s;
for (int i = (int)vec.size()-1; i >= 0; i--){
if (k-sum >= 0 && pre[k-sum])
out[u-n] = 1;
if (i > 0)
sum += vec[i]-vec[i-1];
}
return;
}
add(u, 1);
for (int j = 0; j < adj[u].size(); j++){
int v = adj[u][j];
dfs(v);
}
add(u, -1);
}
int main(){
scanf("%d %d %d %d", &n, &m, &k, &s);
s++;
for (int i = 1; i <= n; i++){
scanf("%d %d", &par[i], &sz[i]);
sz[i]++;
adj[par[i]].pb(i);
}
for (int i = n+1; i <= n+m; i++){
scanf("%d %d", &par[i], &sz[i]);
sz[i]++;
adj[par[i]].pb(i);
}
fix(0);
dfs(0);
for (int i = 1; i <= m; i++){
if (out[i])
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
/*
3 1 10 2
0 1
1 1
2 1
0 2
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |