# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1087342 | Zero_OP | Burza (COCI16_burza) | C++14 | 34 ms | 1056 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |