Submission #218258

# Submission time Handle Problem Language Result Execution time Memory
218258 2020-04-01T17:41:17 Z dolphingarlic File Paths (BOI15_fil) C++14
100 / 100
190 ms 8216 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int n, m, k, s;
vector<int> graph[6060];
int to_root[6060], par[6060], can[2020202], cyc[2020202];
bool good[6060];

void add_cycles(int node, int root, int val) {
    cyc[to_root[node] - to_root[root] + s] += val;
    for (int i : graph[node]) if (i <= n) add_cycles(i, root, val);
}

void dfs(int node = 0) {
    if (node > n) {
        int add_dist = k - to_root[node];
        if (!add_dist) good[node] = true;
        for (int i = 1; i * i <= add_dist; i++)
            if (add_dist % i == 0 && (cyc[i] || cyc[add_dist / i])) good[node] = true;
        for (int i = par[node]; ~i; i = par[i])
            if (add_dist - s + to_root[i] >= 0 && can[add_dist - s + to_root[i]]) good[node] = true;
    }
    add_cycles(node, node, 1);
    for (int i : graph[node]) dfs(i);
    add_cycles(node, node, -1);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> k >> s;
    s++;
    par[0] = -1;
    can[0] = 1;
    FOR(i, 1, n + m + 1) {
        int l;
        cin >> par[i] >> l;
        graph[par[i]].push_back(i);
        to_root[i] = to_root[par[i]] + l + 1;
        if (i <= n) can[to_root[i]]++;
    }
    dfs();

    FOR(i, n + 1, n + m + 1) cout << (good[i] ? "YES\n" : "NO\n");
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 10 ms 3968 KB Output is correct
7 Correct 14 ms 6400 KB Output is correct
8 Correct 9 ms 5120 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 7 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 7552 KB Output is correct
2 Correct 18 ms 7680 KB Output is correct
3 Correct 18 ms 7552 KB Output is correct
4 Correct 17 ms 7680 KB Output is correct
5 Correct 160 ms 8064 KB Output is correct
6 Correct 161 ms 8064 KB Output is correct
7 Correct 98 ms 7288 KB Output is correct
8 Correct 101 ms 7168 KB Output is correct
9 Correct 18 ms 7296 KB Output is correct
10 Correct 16 ms 7040 KB Output is correct
11 Correct 11 ms 768 KB Output is correct
12 Correct 150 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 10 ms 3968 KB Output is correct
7 Correct 14 ms 6400 KB Output is correct
8 Correct 9 ms 5120 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 7 ms 1152 KB Output is correct
13 Correct 17 ms 7552 KB Output is correct
14 Correct 18 ms 7680 KB Output is correct
15 Correct 18 ms 7552 KB Output is correct
16 Correct 17 ms 7680 KB Output is correct
17 Correct 160 ms 8064 KB Output is correct
18 Correct 161 ms 8064 KB Output is correct
19 Correct 98 ms 7288 KB Output is correct
20 Correct 101 ms 7168 KB Output is correct
21 Correct 18 ms 7296 KB Output is correct
22 Correct 16 ms 7040 KB Output is correct
23 Correct 11 ms 768 KB Output is correct
24 Correct 150 ms 3456 KB Output is correct
25 Correct 16 ms 7680 KB Output is correct
26 Correct 16 ms 7552 KB Output is correct
27 Correct 16 ms 7552 KB Output is correct
28 Correct 16 ms 7552 KB Output is correct
29 Correct 162 ms 8064 KB Output is correct
30 Correct 188 ms 8216 KB Output is correct
31 Correct 95 ms 7164 KB Output is correct
32 Correct 110 ms 7168 KB Output is correct
33 Correct 15 ms 7168 KB Output is correct
34 Correct 14 ms 7168 KB Output is correct
35 Correct 10 ms 768 KB Output is correct
36 Correct 190 ms 2168 KB Output is correct