Submission #401583

#TimeUsernameProblemLanguageResultExecution timeMemory
401583ngpin04Burza (COCI16_burza)C++14
160 / 160
12 ms1504 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; const int N = 405; vector <int> tmpadj[N]; vector <int> adj[N]; int par[N][N]; int dp[1 << 20]; int tin[N]; int tout[N]; int id[N]; int h[N]; int n,k,timer; int getbit(int mask, int i) { return (mask >> i) & 1; } void maxi(int &a, int b) { if (a < b) a = b; } bool dfs1(int u, int p) { if (h[u] == k) return true; bool res = false; for (int v : tmpadj[u]) if (v != p) { h[v] = h[u] + 1; int nxt = dfs1(v, u); res |= nxt; if (nxt) adj[u].push_back(v); } return res; } void dfs2(int u, int p) { par[u][0] = u; par[u][1] = p; for (int i = 2; i <= h[u] + 1; i++) par[u][i] = par[par[u][i - 1]][1]; timer++; tin[u] = tout[u] = timer; id[timer] = u; for (int v : adj[u]) if (v != p) dfs2(v, u); tout[u] = timer; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; if (k > 20) return cout << "DA\n", 0; for (int i = 1; i < n; i++) { int u,v; cin >> u >> v; tmpadj[u].push_back(v); tmpadj[v].push_back(u); } if (!dfs1(1, -1)) return cout << "DA\n", 0; dfs2(1, -1); // for (int i = 1; i <= n; i++) // cerr << h[i] << " "; // cerr << timer << "\n"; // for (int i = 1; i <= n; i++) // cerr << tin[i] << " " << tout[i] << "\n"; for (int mask = 0; mask < (1 << k); mask++) { int &res = dp[mask]; while (res <= timer && h[id[res]] < k) res++; if (res > timer) return cout << "DA\n", 0; int u = id[res]; for (int i = 0; i < k; i++) if (!getbit(mask, i)) { int p = par[u][k - (i + 1)]; maxi(dp[mask | (1 << i)], tout[p] + 1); } } 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...