Submission #501385

#TimeUsernameProblemLanguageResultExecution timeMemory
501385DiriiBurza (COCI16_burza)C++14
160 / 160
61 ms51096 KiB
// #pragma GCC target("avx2") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define ll long long #define cll const ll #define lp(a, b, c) for(ll a = b; a <= c; ++a) #define lpd(a, b, c) for(ll a = b; a >= c; --a) #define vec(a) vector<a> #define pp(a, b) pair<a, b> #define EACHCASE lpd(cs, read(), 1) #define Fname "f" using namespace std; template <typename T> inline void Read(T &x){ x = 0; char c; ll dau = 1; while(!isdigit(c = getchar())) if(c == '-') dau = -1; do{ x = x * 10 + c - '0'; } while (isdigit(c = getchar())); x *= dau; } ll read(){ ll tmp; cin >> tmp; return tmp; } void giuncute(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void OF(){ if(fopen(Fname".inp", "r")){ freopen(Fname".inp", "r", stdin); freopen(Fname".out", "w", stdout); } else if(fopen(Fname".in", "r")){ freopen(Fname".in", "r", stdin); freopen(Fname".out", "w", stdout); } } #define yes "DA" #define no "NE" cll mxn = 406; ll n, k, depth[mxn] = {0}, leaves[mxn] = {0}, totleaf = 1; int dp[mxn][1 << 20]; vec(ll) g[mxn]; pp(ll, ll) range[mxn]; vec(pp(ll, ll)) ed_range[mxn]; bool isLeaf[mxn] = {0}; void init(ll u, ll p){ if(depth[u] == k - 1){ leaves[u] = totleaf; range[u] = {totleaf, totleaf + 1}; ++totleaf; isLeaf[u] = 1; ed_range[range[u].second].push_back({range[u].first, depth[u]}); return; } range[u].first = totleaf; for(ll v : g[u]){ if(v == p) continue; depth[v] = depth[u] + 1; init(v, u); } range[u].second = totleaf; if(u != 1) ed_range[range[u].second].push_back({range[u].first, depth[u]}); } bool sol(ll ed, ll mask){ if(ed == 1) return 1; if(~dp[ed][mask]) return dp[ed][mask]; int &cur = dp[ed][mask]; for(auto i : ed_range[ed]){ if((mask & (1 << i.second)) && sol(i.first, mask ^ (1 << i.second))){ return cur = 1; } } return cur = 0; } int main(){ giuncute(); #ifndef ONLINE_JUDGE OF(); #endif cin >> n >> k; lp(i, 1, n - 1){ static ll u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } if(k * k >= n) return cout << yes, 0; depth[1] = -1; init(1, -1); lp(i, 1, totleaf) lp(j, 0, (1 << k) - 1) dp[i][j] = -1; cout << (sol(totleaf, (1 << k) - 1) ? yes : no); }

Compilation message (stderr)

burza.cpp: In function 'bool sol(long long int, long long int)':
burza.cpp:83:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   83 |             return cur = 1;
      |                    ~~~~^~~
burza.cpp:86:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   86 |     return cur = 0;
      |            ~~~~^~~
burza.cpp: In function 'void OF()':
burza.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(Fname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(Fname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(Fname".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(Fname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...