Submission #867321

#TimeUsernameProblemLanguageResultExecution timeMemory
867321KiFaH_HeLaLBurza (COCI16_burza)C++17
0 / 160
387 ms9816 KiB
#include <bits/stdc++.h> #define ll long long #define ld double using namespace std; int n, k, K, last; vector<vector<int> > adj, rng; vector<vector<bool> > dp; vector<int> l, r, d; int inf=1e9; void dfs(int a, int b){ if(a==b)d[a]=0; else d[a]=d[b]+1; if(d[a]==k){ l[a]=++last; r[a]=last; return; } for(auto x:adj[a]){ if(x==b)continue; dfs(x, a); l[a]=min(l[a], l[x]); r[a]=max(r[a], r[x]); } } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int Tc=1;//cin>>Tc; while(Tc--) { cin>>n>>k; adj.assign(n+1, vector<int>()); for(int i=1;i<n;++i){ int u, v;cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } if(k>20){cout<<"NE";continue;} d.assign(n+1, 0); l.assign(n+1, inf); r.assign(n+1, -inf); dfs(1, 1); rng.assign(k+1, vector<int>(last+1, -1) ); for(int i=2;i<=n;++i){ if(l[i]==inf)continue; rng[d[i]][r[i]]=l[i]; } K=(1<<k); dp.assign(K, vector<bool>(last+1, false)); string ans="NE"; dp[0][0]=true; for(int mask=1; mask<K; ++mask){ dp[mask][0]=true; for(int i=1; i<=last; ++i){ for(int j=1, J=1; j<=k; ++j, J<<=1){ if((mask&J)==0)continue; if(rng[j][i]==-1)continue; if(dp[mask^J][rng[j][i]-1]){ dp[mask][i]=true; break; } } } if(dp[mask][last]){ ans="DA"; break; } } cout<<ans; } 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...