Submission #156991

# Submission time Handle Problem Language Result Execution time Memory
156991 2019-10-08T21:07:52 Z luciocf Burza (COCI16_burza) C++14
0 / 160
86 ms 832 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 410;

int n, k;
int nivel[maxn];

int ini[maxn], fim[maxn], tt;

bool dp[maxn][1<<20];

vector<int> grafo[maxn];

void dfs(int u, int p)
{
	if (nivel[u] == k)
	{
		ini[u] = ++tt;
		fim[u] = tt;
		return;
	}

	ini[u] = n+1;

	for (auto v: grafo[u])
	{
		if (v == p) continue;

		nivel[v] = nivel[u]+1;
		dfs(v, u);

		ini[u] = min(ini[u], ini[v]);
		fim[u] = max(fim[u], fim[v]);
	}
}

void dfs2(int u, int p)
{
	for (auto v: grafo[u])
	{
		if (v == p || nivel[v] == k) continue;

		dfs2(v, u);

		for (int mask = 0; mask < (1<<k); mask++)
			if (!(mask&(1<<nivel[v])))
				dp[fim[v]][mask&(1<<nivel[v])] |= dp[ini[v]-1][mask];
	}
}

int main(void)
{
	scanf("%d %d", &n, &k);

	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);

		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}

	if (k >= 20)
	{
		printf("DA\n");
		return 0;
	}

	dfs(1, 0);

	if (tt == 0)
	{
		printf("DA\n");
		return 0;
	}

	for (int mask = 0; mask < (1<<k); mask++)
		dp[0][mask] = 1;

	dfs2(1, 0);

	bool ok = 0;
	for (int mask = 0; mask < (1<<k); mask++)
		ok |= dp[tt][mask];

	if (ok) printf("DA\n");
	else printf("NE\n");
}

Compilation message

burza.cpp: In function 'int main()':
burza.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~
burza.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -