Submission #218125

# Submission time Handle Problem Language Result Execution time Memory
218125 2020-04-01T09:43:01 Z dolphingarlic File Paths (BOI15_fil) C++14
100 / 100
319 ms 8192 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;
    }
    for (int i = node; ~i; i = par[i])
        cyc[to_root[node] - to_root[i] + s]++;
    add_cycles(node, node, 1);

    for (int i : graph[node]) dfs(i);
    
    for (int i = node; ~i; i = par[i])
        cyc[to_root[node] - to_root[i] + s]--;
    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 10 ms 1280 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 10 ms 4992 KB Output is correct
7 Correct 18 ms 6400 KB Output is correct
8 Correct 10 ms 5760 KB Output is correct
9 Correct 9 ms 5760 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 7680 KB Output is correct
2 Correct 17 ms 7680 KB Output is correct
3 Correct 16 ms 7680 KB Output is correct
4 Correct 17 ms 7680 KB Output is correct
5 Correct 269 ms 8192 KB Output is correct
6 Correct 258 ms 8064 KB Output is correct
7 Correct 147 ms 7168 KB Output is correct
8 Correct 150 ms 7168 KB Output is correct
9 Correct 19 ms 7296 KB Output is correct
10 Correct 16 ms 7168 KB Output is correct
11 Correct 13 ms 896 KB Output is correct
12 Correct 250 ms 4732 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 10 ms 1280 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 10 ms 4992 KB Output is correct
7 Correct 18 ms 6400 KB Output is correct
8 Correct 10 ms 5760 KB Output is correct
9 Correct 9 ms 5760 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 17 ms 7680 KB Output is correct
14 Correct 17 ms 7680 KB Output is correct
15 Correct 16 ms 7680 KB Output is correct
16 Correct 17 ms 7680 KB Output is correct
17 Correct 269 ms 8192 KB Output is correct
18 Correct 258 ms 8064 KB Output is correct
19 Correct 147 ms 7168 KB Output is correct
20 Correct 150 ms 7168 KB Output is correct
21 Correct 19 ms 7296 KB Output is correct
22 Correct 16 ms 7168 KB Output is correct
23 Correct 13 ms 896 KB Output is correct
24 Correct 250 ms 4732 KB Output is correct
25 Correct 17 ms 7936 KB Output is correct
26 Correct 16 ms 7552 KB Output is correct
27 Correct 16 ms 7680 KB Output is correct
28 Correct 16 ms 7552 KB Output is correct
29 Correct 267 ms 8064 KB Output is correct
30 Correct 274 ms 7936 KB Output is correct
31 Correct 147 ms 7040 KB Output is correct
32 Correct 148 ms 7040 KB Output is correct
33 Correct 16 ms 7168 KB Output is correct
34 Correct 14 ms 7040 KB Output is correct
35 Correct 13 ms 768 KB Output is correct
36 Correct 319 ms 2552 KB Output is correct