Submission #1025524

#TimeUsernameProblemLanguageResultExecution timeMemory
1025524wenqiBurza (COCI16_burza)C++17
0 / 160
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() int N, K; // adj, effective adj vector<int> adj[405], eadj[405]; int maxdepth[405], depth[405], parents[405], hcnt[405]; int dfs1(int i, int p) { maxdepth[i] = depth[i]; for (int j : adj[i]) { if (j == p) continue; depth[j] = depth[i] + 1; maxdepth[i] = max(maxdepth[i], dfs1(j, i)); } return maxdepth[i]; } void dfs2(int i, int p) { if (depth[i] >= K) return; for (int j : adj[i]) { if (j == p) continue; if (maxdepth[j] >= K) { eadj[i].push_back(j); parents[j] = i; dfs2(j, i); } } } priority_queue<pair<int, int>> pq[405]; void dfs3(int i) { for (int j : eadj[i]) { pq[depth[j]].push({-(hcnt[i] = (int)adj[i].size()), j}); dfs3(j); } } bool dead[405]; bool dfs4(int i) { if (depth[i] >= K) return true; for (int j : eadj[i]) { if (not dead[j] and dfs4(j)) return true; } return false; } void rmrf(int i) { dead[i] = true; if (i == 1) return; int p = parents[i]; hcnt[p]--; bool saved = false; for (int j : eadj[p]) { if (not dead[j]) { pq[depth[j]].push({-hcnt[p], j}); saved = true; } } if (not saved) rmrf(p); } int main(int, const char **) { cin.tie(NULL)->sync_with_stdio(false); cin >> N >> K; for (int i = 1; i < N; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } dfs1(1, 0); dfs2(1, 0); dfs3(1); for (int i = K; i >= 1; i--) { int k = 0; while (pq[i].size()) { auto [w, j] = pq[i].top(); if (not dfs4(j)) { pq[i].pop(); } else { k = j; break; } } if (k and not dead[k]) { rmrf(k); } } cout << (dfs4(1) ? "NE" : "DA"); 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...