Submission #401583

# Submission time Handle Problem Language Result Execution time Memory
401583 2021-05-10T13:52:19 Z ngpin04 Burza (COCI16_burza) C++14
160 / 160
12 ms 1504 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 405;

vector <int> tmpadj[N];
vector <int> adj[N];

int par[N][N];
int dp[1 << 20];
int tin[N];
int tout[N];
int id[N];
int h[N];
int n,k,timer;

int getbit(int mask, int i) {
	return (mask >> i) & 1;
}

void maxi(int &a, int b) {
	if (a < b)
		a = b;
}

bool dfs1(int u, int p) {
	if (h[u] == k)
		return true;
	bool res = false;
	for (int v : tmpadj[u]) if (v != p) {
		h[v] = h[u] + 1;
		int nxt = dfs1(v, u);
		res |= nxt;
		if (nxt)
			adj[u].push_back(v);
	}
	return res;
}

void dfs2(int u, int p) {
	par[u][0] = u;
	par[u][1] = p;
	for (int i = 2; i <= h[u] + 1; i++)
		par[u][i] = par[par[u][i - 1]][1];

	timer++;
	tin[u] = tout[u] = timer;
	id[timer] = u;

	for (int v : adj[u]) 
		if (v != p) 
			dfs2(v, u);

	tout[u] = timer;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	if (k > 20)
		return cout << "DA\n", 0;

	for (int i = 1; i < n; i++) {
		int u,v; cin >> u >> v;
		tmpadj[u].push_back(v);
		tmpadj[v].push_back(u);
	}

	if (!dfs1(1, -1))
		return cout << "DA\n", 0;

	dfs2(1, -1);

	// for (int i = 1; i <= n; i++)
	// 	cerr << h[i] << " ";
	// cerr << timer << "\n";

	// for (int i = 1; i <= n; i++)
	// 	cerr << tin[i] << " " << tout[i] << "\n";

	for (int mask = 0; mask < (1 << k); mask++) {
		int &res = dp[mask];
		while (res <= timer && h[id[res]] < k)
			res++;
		if (res > timer)
			return cout << "DA\n", 0;
		int u = id[res];
		for (int i = 0; i < k; i++) if (!getbit(mask, i)) {
			int p = par[u][k - (i + 1)];
			maxi(dp[mask | (1 << i)], tout[p] + 1); 
		}
	}

	cout << "NE\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 10 ms 1488 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1500 KB Output is correct
2 Correct 11 ms 1496 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 12 ms 1492 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1496 KB Output is correct
2 Correct 10 ms 1484 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 844 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1100 KB Output is correct
2 Correct 11 ms 1484 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1496 KB Output is correct
2 Correct 11 ms 1484 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1504 KB Output is correct
2 Correct 10 ms 1488 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 844 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1504 KB Output is correct
2 Correct 10 ms 1392 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 11 ms 1400 KB Output is correct
6 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 11 ms 1404 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 12 ms 1484 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1100 KB Output is correct
2 Correct 11 ms 1496 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 6 ms 1100 KB Output is correct
6 Correct 1 ms 596 KB Output is correct