제출 #577962

#제출 시각아이디문제언어결과실행 시간메모리
577962Ronin13Burza (COCI16_burza)C++14
160 / 160
358 ms51860 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back #define ull unsigned ll using namespace std; const int NMAX = 401; const int inf = 1e9 + 1; vector <vector <int> > g(NMAX); bool dp[(1 << 20) - 1][NMAX]; int timer = 1; int l[NMAX], r[NMAX]; int k; void dfs(int v, int depth, int e = -1){ if(depth == k){ // cout << v << ' '; l[v] = r[v] = timer; timer++; return; } for(int to : g[v]){ if(to == e) continue; dfs(to, depth + 1, v); l[v] = min(l[v], l[to]); r[v] = max(r[v], r[to]); } } void DFS(int v, int depth = -1, int e = -1){ if(l[v] == inf) return; if(depth != -1){ for(int mask = 0; mask < (1 << (k)); mask++){ if(mask & (1 << depth)) continue; if(dp[mask][l[v] - 1]) dp[mask + (1 << depth)][r[v]] = true; }} for(int to : g[v]){ if(to == e) continue; DFS(to, depth + 1, v); } } int main(){ int n; cin >> n; cin >> k; for(int i = 1; i < n; i++){ int u , v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } for(int i = 1; i <= n; i++){ l[i] = inf; r[i] = 0; } if(k * k > n){ cout << "DA\n"; return 0; } for(int i = 0; i < (1 << k); i++) dp[i][0] = true; dfs(1, 0); /*for(int i = 1; i <= n; i++){ cout << l[i] << ' ' << r[i] << "\n"; }*/ DFS(1); /*for(int i = 1; i < (1 << k); i++){ for(int j = 0; j < timer; j++){ dp[i][j] ? cout << 1 : cout << 0; cout << ' '; } cout << "\n"; }*/ dp[(1 << k) - 1][timer - 1] ? cout << "DA" : 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...