# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
467206 | BeanZ | Burza (COCI16_burza) | C++14 | 14 ms | 1484 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 ll long long
#define endl '\n'
const int N = 405;
long long mod = 1e9 + 7;
const int lim = 4e5 + 5;
const int lg = 21;
const int base = 37;
const long double eps = 1e-6;
ll tin[N], tout[N], par[N][21], in[N], dp[(1 << 21)];
ll timer = 0;
vector<ll> node[N];
ll k;
void dfs(ll u, ll p, ll d){
bool flag = false;
tin[u] = 1e9;
tout[u] = 0;
for (auto j : node[u]){
if (j == p) continue;
for (int i = 1; i <= k; i++){
par[j][i] = par[u][i];
}
if ((d + 1) <= k) par[j][d + 1] = j;
dfs(j, u, d + 1);
tin[u] = min(tin[u], tin[j]);
tout[u] = max(tout[u], tout[j]);
flag = true;
}
if ((d == k) && u != 1){
timer++;
tin[u] = timer;
tout[u] = timer;
in[timer] = u;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("tests.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin >> n >> k;
for (int i = 1; i < n; i++){
ll u, v;
cin >> u >> v;
node[u].push_back(v);
node[v].push_back(u);
}
if ((k * k) >= n) return cout << "DA", 0;
dfs(1, 1, 0);
dp[0] = 0;
for (int i = 1; i < (1 << k); i++){
for (int j = 0; j < k; j++){
if (i & (1 << j)){
ll id = dp[i ^ (1 << j)];
dp[i] = max(dp[i], id);
id++;
dp[i] = max(dp[i], tout[par[in[id]][j + 1]]);
}
}
}
if (dp[(1 << k) - 1] == timer) cout << "DA";
else cout << "NE";
}
/*
6 2
1 2
2 3
3 4
1 5
5 6
Ans:
Out:
*/
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... |