Submission #243443

#TimeUsernameProblemLanguageResultExecution timeMemory
243443NONAMEBurza (COCI16_burza)C++14
160 / 160
273 ms39544 KiB
#include <bits/stdc++.h> #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie() using namespace std; using ll = long long; int n, k; bool f[1 << 21], nf[1 << 21], st[25][1 << 21], mk[1 << 21]; vector <int> g[500]; void dfs1(int v, int pr = -1, int d = -1) { if (d == k - 1) { mk[v] = 1; return; } for (int u : g[v]) if (u != pr) dfs1(u, v, d + 1), mk[v] |= mk[u]; } void dfs2(int v, int pr = 0, int d = -1) { if (!mk[v]) return; if (v) memcpy(st[d], f, sizeof(f)); for (int u : g[v]) if (u != pr) dfs2(u, v, d + 1); if (!v) return; memset(nf, 0, sizeof(nf)); for (int i = 0; i < (1 << k); ++i) if (d == k - 1) { if (!(i & (1 << d))) nf[i | (1 << d)] |= f[i]; } else { nf[i] |= f[i]; if (!(i & (1 << d))) nf[i | (1 << d)] |= st[d][i]; } memcpy(f, nf, sizeof(nf)); } int main() { fast_io; cin >> n >> k; for (int i = 0; i < n - 1; ++i) { int v, u; cin >> v >> u; --v, --u; g[v].push_back(u); g[u].push_back(v); } dfs1(0); if (k * k >= n || !mk[0]) { cout << "DA\n"; return 0; } f[0] = 1; dfs2(0); for (int msk = 0; msk < (1 << k); ++msk) if (f[msk]) { cout << "DA\n"; return 0; } cout << "NE\n"; }
#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...