Submission #583005

# Submission time Handle Problem Language Result Execution time Memory
583005 2022-06-24T16:41:21 Z BackNoob Burza (COCI16_burza) C++14
160 / 160
53 ms 3196 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
 
using namespace std;
const int mxN = 427;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
 
int n;
int k;
int depth[mxN];
int sub[mxN];
int lef[mxN];
int rig[mxN];
bool dp[mxN][(1 << 20) + 7];
vector<int> node[mxN];
vector<int> adj[mxN];
int cnt = 0;

void dfs_pre(int u, int par)
{
	lef[u] = inf;
	rig[u] = -inf;
	if(depth[u] == k) {
		++cnt;
		lef[u] = cnt;
		rig[u] = cnt;
	}
	for(int v : adj[u]) {
		if(v == par) continue;
		depth[v] = depth[u] + 1;
		dfs_pre(v, u);
		minimize(lef[u], lef[v]);
		maximize(rig[u], rig[v]);
	}
}

void dfs(int u, int par)
{
	if(depth[u] > k) return;
	for(int v : adj[u]) {
		if(v == par) continue;
		dfs(v, u);
	}

	if(u == 1 || lef[u] == inf) return;

	int x = depth[u] - 1;
	for(int mask = 0; mask < (1 << k); mask++) {
		if(mask & (1 << x)) {
			if(dp[lef[u] - 1][mask ^ (1 << x)] == true)
				dp[rig[u]][mask] = true;
		}
	}
}

void solve()
{
	cin >> n >> k;
	for(int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	if(k >= 20) cout << "DA" << endl;
	else {
		dp[0][0] = true;
		dfs_pre(1, -1);
		dfs(1, -1);

		bool res = false;
		for(int mask = 0; mask < (1 << k); mask++)
			res |= dp[cnt][mask];

		if(res) cout << "DA";
		else cout << "NE";
	} 
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(TASK".inp" , "r" , stdin);
    //freopen(TASK".out" , "w" , stdout);
 
    int tc = 1;
    //cin >> tc;
    while(tc--) {
    	solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 852 KB Output is correct
2 Correct 49 ms 2484 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2592 KB Output is correct
2 Correct 44 ms 2380 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 45 ms 2928 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2656 KB Output is correct
2 Correct 41 ms 2396 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1236 KB Output is correct
2 Correct 53 ms 3196 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 2160 KB Output is correct
2 Correct 41 ms 2864 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2636 KB Output is correct
2 Correct 43 ms 2716 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2788 KB Output is correct
2 Correct 44 ms 2748 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 49 ms 2892 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1236 KB Output is correct
2 Correct 51 ms 2800 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 736 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 728 KB Output is correct
2 Correct 46 ms 2892 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1588 KB Output is correct
2 Correct 45 ms 2840 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 18 ms 1620 KB Output is correct
6 Correct 1 ms 608 KB Output is correct