Submission #1087342

#TimeUsernameProblemLanguageResultExecution timeMemory
1087342Zero_OPBurza (COCI16_burza)C++14
160 / 160
34 ms1056 KiB
#include<bits/stdc++.h> using namespace std; #define sz(v) (int)v.size() #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define dbg(v) "[" #v " = " << (v) << "]" #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define rep(i, l, r) for(int i = (l); i < (r); ++i) using ll = long long; using vi = vector<int>; using vl = vector<long long>; using ld = long double; template<typename T> bool minimize(T& a, const T& b){ if(a > b){ return a = b, true; } return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b){ return a = b, true; } return false; } template<int dimension, typename T> struct tensor : public vector<tensor<dimension - 1, T>> { static_assert(dimension > 0, "Dimension must be positive !\n"); template<typename... Args> tensor(int n = 0, Args... args) : vector<tensor<dimension - 1, T>> (n, tensor<dimension - 1, T>(args...)) {} }; template<typename T> struct tensor<1, T> : public vector<T> { tensor(int n = 0, T val = T()) : vector<T>(n, val) {} }; const int MAX = 405; int n, k, tin[MAX], tout[MAX], depth[MAX], numLeaves; vector<int> adj[MAX]; bitset<1 << 20> dp[MAX]; vector<int> jumpList[MAX]; void dfs(int u, int pre){ if(depth[u] == k){ tin[u] = numLeaves++; tout[u] = numLeaves; } else{ tin[u] = numLeaves; for(int v : adj[u]) if(v != pre){ depth[v] = depth[u] + 1; dfs(v, u); } tout[u] = numLeaves; } //node u contain the leaves from [tin[u], tout[u]) if(u != 1) jumpList[tin[u]].push_back(u); } void testcase(){ cin >> n >> k; 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 * k >= n){ cout << "DA\n"; return; } depth[1] = 0; dfs(1, -1); if(numLeaves == 0){ cout << "DA\n"; return; } dp[0][0] = true; for(int i = 0; i < numLeaves; ++i){ for(int mask = 0; mask < (1 << k); ++mask){ if(!dp[i][mask]) continue; for(int u : jumpList[i]){ if(mask >> (depth[u] - 1) & 1) continue; dp[tout[u]][mask | (1 << (depth[u] - 1))] = true; } } } for(int mask = 0; mask < (1 << k); ++mask){ if(dp[numLeaves][mask]){ cout << "DA\n"; return; } } cout << "NE\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); file("task"); int T = 1; // cin >> T; while(T--){ testcase(); } return 0; }

Compilation message (stderr)

burza.cpp: In function 'int main()':
burza.cpp:9:55: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:117:6: note: in expansion of macro 'file'
  117 |      file("task");
      |      ^~~~
burza.cpp:9:88: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:117:6: note: in expansion of macro 'file'
  117 |      file("task");
      |      ^~~~
#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...