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 <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <deque>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 405;
vector<int> g[maxn];
int dp[1 << 20];
int n, k;
int cnt, lf[maxn], rf[maxn];
vector<int> depth[maxn];
void dfs(int u, int fa, int dep) {
depth[dep].push_back(u);
if (dep == k) {
lf[u] = rf[u] = ++cnt;
return;
}
lf[u] = inf, rf[u] = -inf;
for (int v : g[u]) {
if (v == fa) continue;
dfs(v, u, dep + 1);
lf[u] = min(lf[u], lf[v]);
rf[u] = max(rf[u], rf[v]);
}
}
int main() {
cin >> n >> k;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
if (n <= k * k) {
cout << "DA" << endl;
return 0;
}
dfs(1, 0, 0);
for (int s = 1; s < (1 << k); s++) {
for (int i = 0; i < k; i++) {
if (~s & (1 << i)) continue;
int pre = dp[s ^ (1 << i)];
for (int u : depth[i + 1]) {
if (lf[u] <= pre + 1) {
dp[s] = max(dp[s], rf[u]);
}
}
}
if (dp[s] >= cnt) {
cout << "DA" << endl;
return 0;
}
}
cout << "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... |