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;
int rd() {
bool neg = 0; char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) if(c == '-') neg = !neg;
int n = 0; while('0' <= c && c <= '9') n = (n << 3) + (n << 1) + c - '0', c = getchar();
return neg ? -n : n;
}
void wr(int n) {
static char o[11];
if(n < 0) putchar('-'), n = -n;
int i = 0; do o[i++] = n % 10 + '0'; while(n /= 10);
while(i--) putchar(o[i]);
}
const int N = 402;
const int K = 20;
int n, k, t = 0, tin[N], tout[N], d[N];
bool f[N][1 << K];
vector<int> aj[N], ver[N];
void dfs(int v, int p) {
if(d[v] == k) {
tin[v] = t;
tout[v] = ++t;
}
else {
tin[v] = t;
for(int u : aj[v]) {
if(u == p) {
continue;
}
d[u] = d[v] + 1;
dfs(u, v);
}
tout[v] = t;
}
}
int main() {
n = rd();
k = rd();
if(k * k >= n) {
puts("DA");
return 0;
}
for(int i = 1, u, v; i < n; ++i) {
u = rd();
v = rd();
aj[u].push_back(v);
aj[v].push_back(u);
}
d[1] = 0;
dfs(1, 0);
for(int i = 2; i <= n; ++i) {
if(tin[i] != tout[i]) {
ver[tin[i]].push_back(i);
}
}
f[0][0] = 1;
for(int i = 0; i < t; ++i) {
for(int j = 1 << k; j--; ) {
if(f[i][j]) {
for(int v : ver[i]) {
if(j >> (d[v] - 1) & 1) {
continue;
}
f[tout[v]][j | (1 << (d[v] - 1))] = 1;
}
}
}
}
for(int i = 1 << k; i--; ) {
if(f[t][i]) {
puts("DA");
return 0;
}
}
puts("NE");
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... |