Submission #1103913

#TimeUsernameProblemLanguageResultExecution timeMemory
1103913dead0neBurza (COCI16_burza)C++17
160 / 160
96 ms48456 KiB
#pragma GCC optimize("unroll-loops,Ofast,O3") #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define spc << " " << #define endl "\n" #define all(x) x.begin(), x.end() #define int long long #define ii pair<long long,int> #define vi vector<int> #define vii vector<ii> #define st first #define nd second #define mid (l+r)/2 #define inf 1e15 #define MOD 1000000007 #define MX 405 using namespace std; int n,k; int cnt=0, tim=0; vi edges[MX], ed1[MX], dep(MX), ind(MX), revind(MX), paro(MX); void dfs(int node, int par){ for(auto i:ed1[node]){ if(i==par) continue; dep[i]=dep[node]+1; dfs(i, node); } if(edges[node].size() || dep[node]==k){ cnt++; if(par!=0){ edges[node].pb(par); edges[par].pb(node); } } } void dfs2(int node, int par){ paro[node]=par; ind[node]=++tim; revind[ind[node]]=node; for(auto i:edges[node]) if(i!=par) dfs2(i, node); } void solve(){ cin >> n >> k; for(int i=1; i<n; i++){ int a,b; cin >> a >> b; ed1[a].pb(b); ed1[b].pb(a); } dep[1]=0; dfs(1,0); n=cnt; if(k*k>=n){ cout << "DA\n"; return; } dfs2(1, 0); bool dp[n+1][1<<k]; memset(dp,0,sizeof(dp)); int lolol[n+1]; lolol[1]=1; for(int i=2; i<=n; i++){ if(i-1==ind[paro[revind[i]]]) lolol[i]=lolol[i-1]; else lolol[i]=i; } for(int i=2; i<=n; i++){ for(int j=0; j<1<<k; j++){ dp[i][j]|=dp[ind[paro[revind[i]]]][j]; if(j&(1<<(dep[revind[i]]-1))) dp[i][j]|=lolol[i]==1?1:dp[lolol[i]-1][j^(1<<(dep[revind[i]]-1))]; } } if(dp[n][(1<<k)-1]) cout << "DA\n"; else cout << "NE\n"; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif /*freopen(".in","r",stdin); freopen(".out","w",stdout);*/ int t=1; //cin >> t; while(t--) solve(); }
#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...