Submission #926565

#TimeUsernameProblemLanguageResultExecution timeMemory
926565MinaRagy06Burza (COCI16_burza)C++17
160 / 160
48 ms1112 KiB
#include <bits/stdc++.h> using namespace std; const int N = 405; vector<int> adj[N]; int par[N], dep[N], t; array<int, 2> v[N]; int n, k; vector<int> gud[N]; void dfs(int i, int p, int d) { for (auto nxt : adj[i]) { if (nxt == p) continue; dfs(nxt, i, d + 1); v[i][0] = min(v[i][0], v[nxt][0]); v[i][1] = max(v[i][1], v[nxt][1]); } dep[i] = d; if (d == k) { v[i][0] = min(v[i][0], t); v[i][1] = max(v[i][1], t); t++; } if (v[i][0] != n + 1) { par[i] = p; gud[d].push_back(i); } } int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> k; if (n <= k * k) { cout << "DA\n"; return 0; } for (int i = 1, u, v; i < n; i++) { cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; i++) { v[i] = {n + 1, -1}; } dfs(1, 0, 0); for (int i = 1; i <= n; i++) adj[i].clear(); for (int i = 1; i <= n; i++) { if (!par[i]) continue; adj[par[i]].push_back(i); } // for (int i = 1; i <= k; i++) { // for (auto j : gud[i]) { // cout << v[j][0] << ", " << v[j][1] << '\n'; // } // cout << '\n'; // } int m = 1 << k, dp[m]; dp[0] = -1; for (int msk = 1; msk < m; msk++) { dp[msk] = -1; for (int j = 1; j <= k; j++) { if (!((msk >> (j - 1)) & 1)) continue; for (auto i : gud[j]) { if (v[i][0] <= dp[msk ^ (1 << (j - 1))] + 1) { dp[msk] = max(dp[msk], v[i][1]); } } } } if (dp[m - 1] == t - 1) { cout << "DA\n"; } else { cout << "NE\n"; } 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...