# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501385 | Dirii | Burza (COCI16_burza) | C++14 | 61 ms | 51096 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.
// #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)
# | 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... |