Submission #1110845

# Submission time Handle Problem Language Result Execution time Memory
1110845 2024-11-10T15:34:30 Z Rainmaker2627 File Paths (BOI15_fil) C++17
100 / 100
126 ms 16572 KB
#include<bits/stdc++.h>
using namespace std;

int n, m, k, s;
vector<bool> ans;
vector<int> dist, par, cyc, skip;
vector<vector<int>> chl;

void add(int u, int p, int v) {
	if (u>n) return;
	cyc[dist[u]-dist[p]+s]+=v;
	for (auto i : chl[u]) add(i, p, v);
}

void dfs(int u) {
	if (u>n) {
		int d=k-dist[u];
		if (d==0) ans[u]=true;
		for (int i = 1; i*i <= d; ++i) if (d%i==0 && (cyc[i] || cyc[d/i])) ans[u]=true;
		for (int i = par[u]; i >= 0; i=par[i]) if (d-s+dist[i]>=0 && skip[d-s+dist[i]]) ans[u]=true;
	} else {
		add(u, u, 1);
		for (auto v : chl[u]) dfs(v);
		add(u, u, -1);
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(false);

	cin >> n >> m >> k >> s; s++;
	cyc.assign(2*k+1, 0);
	skip.assign(2*k+1, 0); skip[0]=1;
	dist.assign(n+m+1, 0);
	par.assign(n+m+1, 0); par[0]=-1;
	ans.assign(n+m+1, false);
	chl.assign(n+m+1, vector<int>());

	for (int i = 1; i <= n+m; ++i) {
		int p, l;
		cin >> p >> l;
		par[i]=p;
		chl[p].push_back(i);
		dist[i]=dist[p]+l+1;
		if (i<=n) skip[dist[i]]++;
	}

	dfs(0);
	for (int i = n+1; i <= n+m; ++i) {
		cout << (ans[i]?"YES":"NO") << '\n';
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 3 ms 1872 KB Output is correct
4 Correct 4 ms 1872 KB Output is correct
5 Correct 8 ms 15952 KB Output is correct
6 Correct 7 ms 15952 KB Output is correct
7 Correct 10 ms 16172 KB Output is correct
8 Correct 6 ms 15952 KB Output is correct
9 Correct 6 ms 16168 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 6 ms 14672 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16208 KB Output is correct
2 Correct 10 ms 16208 KB Output is correct
3 Correct 10 ms 16464 KB Output is correct
4 Correct 10 ms 16208 KB Output is correct
5 Correct 95 ms 16568 KB Output is correct
6 Correct 94 ms 16572 KB Output is correct
7 Correct 56 ms 16464 KB Output is correct
8 Correct 57 ms 16464 KB Output is correct
9 Correct 10 ms 16464 KB Output is correct
10 Correct 12 ms 16464 KB Output is correct
11 Correct 8 ms 14928 KB Output is correct
12 Correct 96 ms 14976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 3 ms 1872 KB Output is correct
4 Correct 4 ms 1872 KB Output is correct
5 Correct 8 ms 15952 KB Output is correct
6 Correct 7 ms 15952 KB Output is correct
7 Correct 10 ms 16172 KB Output is correct
8 Correct 6 ms 15952 KB Output is correct
9 Correct 6 ms 16168 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 6 ms 14672 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 10 ms 16208 KB Output is correct
14 Correct 10 ms 16208 KB Output is correct
15 Correct 10 ms 16464 KB Output is correct
16 Correct 10 ms 16208 KB Output is correct
17 Correct 95 ms 16568 KB Output is correct
18 Correct 94 ms 16572 KB Output is correct
19 Correct 56 ms 16464 KB Output is correct
20 Correct 57 ms 16464 KB Output is correct
21 Correct 10 ms 16464 KB Output is correct
22 Correct 12 ms 16464 KB Output is correct
23 Correct 8 ms 14928 KB Output is correct
24 Correct 96 ms 14976 KB Output is correct
25 Correct 11 ms 16396 KB Output is correct
26 Correct 10 ms 16208 KB Output is correct
27 Correct 9 ms 16376 KB Output is correct
28 Correct 9 ms 16208 KB Output is correct
29 Correct 99 ms 16464 KB Output is correct
30 Correct 95 ms 16464 KB Output is correct
31 Correct 58 ms 16464 KB Output is correct
32 Correct 58 ms 16464 KB Output is correct
33 Correct 10 ms 16208 KB Output is correct
34 Correct 9 ms 16252 KB Output is correct
35 Correct 9 ms 16272 KB Output is correct
36 Correct 126 ms 15192 KB Output is correct