Submission #242903

#TimeUsernameProblemLanguageResultExecution timeMemory
242903VEGAnnBurza (COCI16_burza)C++14
160 / 160
65 ms3320 KiB
#include <bits/stdc++.h> #define PB push_back #define i2 array<int,2> using namespace std; const int N = 410; const int PW = (1 << 20); vector<int> g[N]; vector<i2> qr[N]; bool dp[N][PW]; int cnt, h[N], sta[N], ed[N], n, k; void dfs(int v, int p){ if (h[v] == k - 1){ sta[v] = cnt++; ed[v] = cnt; qr[sta[v]].PB({v, ed[v]}); return; } sta[v] = cnt; for (int u : g[v]){ if (u == p) continue; h[u] = h[v] + 1; dfs(u, v); } if (v > 0) { ed[v] = cnt; qr[sta[v]].PB({v, ed[v]}); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n >> k; if (k * k >= n){ cout << "DA"; return 0; } for (int i = 1; i < n; i++){ int x, y; cin >> x >> y; x--; y--; g[x].PB(y); g[y].PB(x); } h[0] = -1; dfs(0, -1); dp[0][0] = 1; for (int i = 0; i < cnt; i++) for (int msk = 0; msk < (1 << k); msk++){ if (!dp[i][msk]) continue; for (i2 cr : qr[i]) { int v = cr[0]; int j = cr[1]; if (!(msk & (1 << h[v]))) dp[j][msk + (1 << h[v])] = 1; } } for (int msk = 0; msk < (1 << k); msk++) if (dp[cnt][msk]) { cout << "DA"; return 0; } cout << "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...