Submission #726157

# Submission time Handle Problem Language Result Execution time Memory
726157 2023-04-18T15:03:56 Z dozer File Paths (BOI15_fil) C++14
0 / 100
16 ms 29124 KB
#include <bits/stdc++.h>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define L(node) node * 2
#define R(node) node * 2 + 1
#define N 1000005
#define int long long

int sum[N], done[N];

int len[N], par[N], file[N], len2[N], path[N];
vector<int> child[N];

void dfs(int node, int d)
{
	d += len[node];
	path[node] = d;
	done[d] = 1;
	for (auto i : child[node])
		dfs(i, d);
}

int32_t main()
{
	fastio();


	int n, m, k;
	cin>>n>>m>>k;
	int s;
	cin>>s;
	s++;
	len[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		cin>>par[i]>>len[i];
		len[i]++;
		child[par[i]].pb(i);
	}

	for (int i = 1; i <= m; i++)
		cin>>file[i]>>len2[i];

	dfs(0, 0);

	for (int i = 0; i <= n; i++)
		assert(path[i] <= k);

	for (int i = 1; i <= m; i++)
	{
		int sum = len2[i];
		int flag = 0;
		if (sum + path[file[i]] == k) flag = 1;
		int curr = file[i];
		while(curr != 0)
		{
			if (k >= sum + s && done[k - sum - s]) flag = 1;
			sum += len[curr];
			curr = par[curr];
		}
		sum++;
		if (flag) cout<<"YES\n";
		else cout<<"NO\n";
	}

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 23804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 29124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 23804 KB Output isn't correct
2 Halted 0 ms 0 KB -