이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;
int n, k;
bool f[1 << 21], nf[1 << 21], st[25][1 << 21], mk[1 << 21];
vector <int> g[500];
void dfs1(int v, int pr = -1, int d = -1) {
if (d == k - 1) {
mk[v] = 1;
return;
}
for (int u : g[v])
if (u != pr)
dfs1(u, v, d + 1), mk[v] |= mk[u];
}
void dfs2(int v, int pr = 0, int d = -1) {
if (!mk[v])
return;
if (v)
memcpy(st[d], f, sizeof(f));
for (int u : g[v])
if (u != pr)
dfs2(u, v, d + 1);
if (!v)
return;
memset(nf, 0, sizeof(nf));
for (int i = 0; i < (1 << k); ++i)
if (d == k - 1) {
if (!(i & (1 << d)))
nf[i | (1 << d)] |= f[i];
} else {
nf[i] |= f[i];
if (!(i & (1 << d)))
nf[i | (1 << d)] |= st[d][i];
}
memcpy(f, nf, sizeof(nf));
}
int main() {
fast_io;
cin >> n >> k;
for (int i = 0; i < n - 1; ++i) {
int v, u;
cin >> v >> u;
--v, --u;
g[v].push_back(u);
g[u].push_back(v);
}
dfs1(0);
if (k * k >= n || !mk[0]) {
cout << "DA\n";
return 0;
}
f[0] = 1;
dfs2(0);
for (int msk = 0; msk < (1 << k); ++msk)
if (f[msk]) {
cout << "DA\n";
return 0;
}
cout << "NE\n";
}
# | 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... |