Submission #555737

#TimeUsernameProblemLanguageResultExecution timeMemory
555737new_accZapina (COCI20_zapina)C++14
0 / 110
1 ms340 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=400+10; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=20; bitset<(1<<20)+1> dp[N*2][2]; bool pod[N],level[N]; vi graf[N]; int n,k,wsk,pierw[N]; void dfs(int v,int o){ if(level[v]==k) pod[v]=1; for(auto u:graf[v]){ if(u==o) continue; level[u]=level[v]+1; dfs(u,v); pod[v]|=pod[u]; } } void dfs2(int v,int o){ wsk++; pierw[v]=wsk; if(v!=1){ for(int i=0;i<(1<<(k+1));i++){ if(i&(1<<level[v])) dp[wsk][1][i]=min(dp[wsk-1][1][i],dp[wsk-1][0][i-(1<<level[v])]); else dp[wsk][1][i]=dp[wsk-1][1][i]; } if(level[v]!=k) dp[wsk][0]=dp[wsk-1][0]; else dp[wsk][0]=dp[wsk][1]; } for(auto u:graf[v]){ if(u==o or !pod[u] or level[u]>k) continue; dfs2(u,v); } if(v==1) return; wsk++; dp[wsk][0]=dp[wsk-1][0],dp[wsk][1]=dp[pierw[o]][1]; } void solve(){ cin>>n>>k; for(int a,b,i=1;i<n;i++){ cin>>a>>b; graf[a].push_back(b),graf[b].push_back(a); } if(k*k>=n){ cout<<"DA\n"; return; } dfs(1,1); for(int i=0;i<(1<<(k+1));i++) dp[1][0][i]=1; dfs2(1,1); cout<<(dp[wsk][0][(1<<(k+1))-1]?"DA":"NE")<<"\n"; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...