Submission #936535

#TimeUsernameProblemLanguageResultExecution timeMemory
936535parsadox2Burza (COCI16_burza)C++17
0 / 160
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int N = 4e2 + 10 , Lg = 10; int n , k , dp[N][(1 << Lg)] , dis[N]; vector <int> adj[N]; void Dfs(int v , int p = 0) { for(auto u : adj[v]) if(u != p) { dis[u] = dis[v] + 1; Dfs(u , v); } //cout << v << " " << dis[v] << ":: " << endl; for(int mask = 0 ; mask < (1 << k) ; mask++) { bool flg = false; for(int i = 0 ; i <= min(k - 1 , dis[v]) ; i++) if((mask >> i) & 1) flg = true; if(flg) dp[v][mask] = -N; else dp[v][mask] = dis[v]; } for(auto u : adj[v]) if(u != p) { for(int mask = (1 << k) - 1 ; mask > -1 ; mask--) { if(dp[v][mask] == -N) break; dp[v][mask] = max(dp[v][mask] , dp[u][0]); for(int s = mask ; s > 0 ; s = ((s - 1) & mask)) dp[v][mask] = min(dp[v][mask] , max(dp[v][mask - s] , dp[u][s])); } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 0 ; i < n - 1 ; i++) { int u , v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } if(k >= Lg) { cout << "DA" << '\n'; return 0; } dis[1] = -1; Dfs(1); cout << (dp[1][(1 << k) - 1] < k - 1 ? "DA" : "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...