Submission #885561

#TimeUsernameProblemLanguageResultExecution timeMemory
885561parlimoosBurza (COCI16_burza)C++14
0 / 160
1 ms348 KiB
//Be Name KHODA #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define pp pop_back #define lb lower_bound #define ub upper_bound #define cl clear #define bg begin #define arr(x) array<int , x> #define endl '\n' int n , k; vector<int> tr[400]; int cnt[20]; int hs[400]; void init(){ fill(&hs[0] , &hs[n] , -1); queue<int> q; q.push(0); hs[0] = 0; while(!q.empty()){ int v = q.front(); q.pop(); for(int u : tr[v]){ if(hs[u] == -1){ hs[u] = hs[v] + 1; q.push(u); } } } } bool jg(int msk){ // cout << msk << "::\n" << flush; queue<int> q; q.push(0); while(!q.empty()){ int v = q.front(); // cout << v << ",\n" << flush; q.pop(); if(hs[v] >= k) return false; for(int u : tr[v]){ if(hs[u] < hs[v] or ((msk >> u) & 1)) continue; q.push(u); } } return true; } void f(){ for(int msk = 0 ; msk < (1 << n) ; msk++){ fill(&cnt[0] , &cnt[n] , 0); bool flg = 1; for(int i = 0 ; i < n ; i++){ if((msk >> i) & 1){ cnt[hs[i]]++; if(cnt[hs[i]] > 1){ flg = 0; break; } } } if(!flg) continue; if(jg(msk)){ cout << "DA"; exit(0); } } cout << "NE"; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i = 1 ; i < n ; i++){ int v , u; cin >> v >> u; v-- , u--; tr[v].pb(u) , tr[u].pb(v); } if(k >= 20) cout << "DA"; init(); f(); // for(int i = 0 ; i < n ; i++){ // cout << i << " : "; // for(int j = 0 ; j < 10 ; j++) cout << dp[i][j] << " "; // cout << endl; // } }
#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...