Submission #945282

#TimeUsernameProblemLanguageResultExecution timeMemory
945282TrendBattlesBurza (COCI16_burza)C++14
0 / 160
1 ms1628 KiB
//https://oj.uz/problem/view/COCI16_burza #include <bits/stdc++.h> using namespace std; using lli = int64_t; const int MAX_N = 400 + 5; int dp[MAX_N][MAX_N][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector <vector <int>> graph(n + 1); for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } vector <int> parent(n + 1); auto DFS = [&] (auto DFS, int u) -> void { int leaf = true; for (int v : graph[u]) { if (v == parent[u]) continue; parent[v] = u; leaf = false; DFS(DFS, v); } if (leaf) { for (int i = 1; i <= k; ++i) dp[u][i][1] = true; dp[u][0][0] = true; return; } dp[u][0][0] = true; for (int plays = 1; plays <= k; ++plays) { dp[u][plays][0] = true; dp[u][plays][1] = true; for (int v : graph[u]) { if (v == parent[u]) continue; dp[u][plays][1] &= not dp[v][plays - 1][0]; int current = false; for (int t : graph[u]) { if (v == t or t == parent[u]) continue; current |= not dp[t][plays][1]; } dp[u][plays][0] &= current; } } // cerr << "DEBUG: " << u << '\n'; // for (int plays = 0; plays <= k; ++plays) cerr << dp[u][plays][0] << ' ' << dp[u][plays][1] << '\n'; }; DFS(DFS, 1); int ans = dp[1][k][1]; cout << (ans ? "DA" : "NE"); return 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...