Submission #218259

# Submission time Handle Problem Language Result Execution time Memory
218259 2020-04-01T17:46:46 Z dolphingarlic File Paths (BOI15_fil) C++14
100 / 100
184 ms 8064 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 8 ms 1280 KB Output is correct
5 Correct 10 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 8 ms 5300 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 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 17 ms 7552 KB Output is correct
3 Correct 16 ms 7552 KB Output is correct
4 Correct 17 ms 7552 KB Output is correct
5 Correct 177 ms 8064 KB Output is correct
6 Correct 160 ms 8056 KB Output is correct
7 Correct 97 ms 7168 KB Output is correct
8 Correct 98 ms 7172 KB Output is correct
9 Correct 18 ms 7168 KB Output is correct
10 Correct 16 ms 7040 KB Output is correct
11 Correct 10 ms 768 KB Output is correct
12 Correct 145 ms 3448 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 8 ms 1280 KB Output is correct
5 Correct 10 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 8 ms 5300 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 7 ms 1152 KB Output is correct
13 Correct 17 ms 7552 KB Output is correct
14 Correct 17 ms 7552 KB Output is correct
15 Correct 16 ms 7552 KB Output is correct
16 Correct 17 ms 7552 KB Output is correct
17 Correct 177 ms 8064 KB Output is correct
18 Correct 160 ms 8056 KB Output is correct
19 Correct 97 ms 7168 KB Output is correct
20 Correct 98 ms 7172 KB Output is correct
21 Correct 18 ms 7168 KB Output is correct
22 Correct 16 ms 7040 KB Output is correct
23 Correct 10 ms 768 KB Output is correct
24 Correct 145 ms 3448 KB Output is correct
25 Correct 16 ms 7552 KB Output is correct
26 Correct 15 ms 7424 KB Output is correct
27 Correct 15 ms 7552 KB Output is correct
28 Correct 16 ms 7552 KB Output is correct
29 Correct 161 ms 8064 KB Output is correct
30 Correct 166 ms 7936 KB Output is correct
31 Correct 100 ms 7040 KB Output is correct
32 Correct 95 ms 7160 KB Output is correct
33 Correct 15 ms 7168 KB Output is correct
34 Correct 14 ms 7040 KB Output is correct
35 Correct 10 ms 640 KB Output is correct
36 Correct 184 ms 1920 KB Output is correct