Submission #229246

#TimeUsernameProblemLanguageResultExecution timeMemory
229246MetBBurza (COCI16_burza)C++14
16 / 160
875 ms26096 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define N 1000003 using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3; int n, k, ptr; bitset <1 << 21> d[400]; vector <int> g[N]; vector < pair <int, int> > v[400]; pair <int, int> dfs (int x, int p, int h) { if (h == k) { if (h) v[++ptr].push_back ({ptr, h - 1}); return {ptr, ptr}; } int l = 0, r = 0; for (int to : g[x]) { if (to != p) { auto a = dfs (to, x, h + 1); if (!l) l = a.first; r = a.second; } } if (h && l) v[r].push_back ({l, h - 1}); return {l, r}; } int main () { cin >> n >> k; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--, b--; g[a].push_back (b); g[b].push_back (a); } if (k * k >= n) { cout << "DA"; return 0; } dfs (0, -1, 0); d[0][0] = 1; for (int i = 1; i <= ptr; i++) { for (int j = 1; j < (1 << k); j++) { for (int b = 0; b < k; b++) if (j & (1 << b)) d[i][j] = d[i][j] | d[i][j - (1 << b)]; if (d[i][j]) continue; for (auto a : v[i]) { if (j & (1 << a.second)) { d[i][j] = d[i][j] | d[a.first - 1][j ^ (1 << a.second)]; } } } } for (int j = 0; j < (1 << k); j++) if (d[ptr][j]) { cout << "DA"; return 0; } cout << "NE"; }
#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...