Submission #407394

#TimeUsernameProblemLanguageResultExecution timeMemory
407394CrouchingDragonBurza (COCI16_burza)C++17
160 / 160
194 ms6768 KiB
#include "bits/stdc++.h" using namespace std; #define endl '\n' #define debug(x) cerr << #x << " == " << (x) << '\n'; #define all(x) begin(x), end(x) using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, K; cin >> N >> K; if (K * K > N) { cout << "DA" << endl; exit(0); } vector<vector<int>> E(N); for (int i = 0; i < N - 1; ++i) { int u, v; cin >> u >> v; --u, --v; E[u].push_back(v), E[v].push_back(u); } vector<int> h(N), L(N), R(N), V; int timer = 0; auto dfs = [&](auto&& self, int u, int p) -> void { L[u] = timer; if (h[u] < K) { for (auto v : E[u]) { if (v != p) { h[v] = h[u] + 1; self(self, v, u); } } } R[u] = timer++; V.push_back(u); }; h[0] = -1; dfs(dfs, 0, -1); vector<vector<bool>> memo(N); vector<bool> dp(1 << K), dpnxt(1 << K); dp[0] = true; V.pop_back(); for (auto u : V) { if (L[u] > 0) { for (int mask = 0; mask < (1 << K); ++mask) { if (memo[L[u] - 1][mask] && (mask >> h[u] & 1) == 0) { dpnxt[mask | 1 << h[u]] = true; } } } else dpnxt[1 << h[u]] = true; if (h[u] < K - 1) { for (int mask = 0; mask < (1 << K); ++mask) { dpnxt[mask] = dpnxt[mask] || dp[mask]; } } fill(all(dp), false), swap(dp, dpnxt); memo[R[u]] = dp; } string ans = count(all(dp), true) ? "DA" : "NE"; cout << ans << endl; exit(0); }
#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...