Submission #582838

#TimeUsernameProblemLanguageResultExecution timeMemory
582838NeosBurza (COCI16_burza)C++14
32 / 160
93 ms12576 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using ii = pair<int, int>; #define fastIO ios::sync_with_stdio(0); cin.tie(0); #define fi first #define se second #define pb push_back #define numBit(x) (__builtin_popcountll(1ll * (x))) #define getBit(x, i) ((x) >> (i) & 1) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() template<class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + eps < y) { x = y; return true; } else return false; } const int N = 4e2 + 7, oo = 1e9 + 7; int n, k, m, timer, ans, l[N], r[N], dp[N][1 << 20]; vector<int> adj[N]; void euler(int u, int par = -1, int depth = 1) { if (depth == k) { l[u] = r[u] = ++timer; return; } for (int v: adj[u]) if (v != par) { euler(v, u, depth + 1); maximize(r[u], r[v]); minimize(l[u], l[v]); } } void dfs(int u, int par = -1, int depth = 1) { if (depth >= k) return; for (int v: adj[u]) if (v != par) { dfs(v, u, depth + 1); if (l[v] == oo) continue; for (int i = 0; i < (1 << k); i++) if (!getBit(i, depth)) dp[r[v]][i | (1 << depth)] |= dp[l[v] - 1][i]; } } signed main() { fastIO; //#ifndef ONLINE_JUDGE // freopen("test.inp", "r", stdin); // freopen("test.out", "w", stdout); //#endif cin >> n >> k; if (k * k >= n) { cout << "DA\n"; return 0; } for (int i = 0; i < (1 << k); i++) dp[0][i] = 1; for (int i = 1; i <= n; i++) l[i] = oo, r[i] = 0; for (int i = 0, u, v; i < n - 1; i++) { cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } euler(1), dfs(1); // cerr << dp[timer][(1 << m) - 1] << endl; cout << (!dp[timer][(1 << k) - 1] ? "NE" : "DA"); } /* dp[i][mask] = can you "block out" of the first i "depth-k" nodes just blocking nodes have depth in "mask" */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...