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;
using ll = long long;
int N, K;
ll best[401][401]; // cant mark node till xth turn
ll dp[1 << 21];
vector<int> adj[401];
int depth[401];
void dfs(int node, int p, int d)
{
vector<int> paths;
for (int i : adj[node])
{
if (i == p)
continue;
dfs(i, node, d + 1);
depth[node] = max(depth[node], depth[i]);
if (depth[i] >= K)
paths.push_back(i);
}
int n = paths.size();
for (int move = 1; move <= K; ++move) // start marking till move'th move
{
if (move <= d)
best[node][move] = 1;
else if (n > K - move + 1)
best[node][move] = 1e9;
else
{
for (int mask = 1; mask < (1 << n); ++mask)
{
dp[mask] = 1e9;
for (int i = 0; i < n; ++i)
if (mask & (1 << i))
{
int cur_move = move + dp[mask ^ (1 << i)];
if (cur_move > K) // not possible
continue;
dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + best[paths[i]][cur_move]);
}
}
best[node][move] = dp[(1 << n) - 1];
}
}
depth[node] = max(depth[node], d);
}
int main()
{
cin.tie(NULL) -> sync_with_stdio(false);
cin >> N >> K;
for (int i = 1; i < N; ++i)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, 0, 0);
if (K * K >= N)
cout << "DA" << endl;
else
cout << (best[1][1] <= K ? "DA" : "NE") << endl;
return 0;
}
# | 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... |