#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define N 1000003
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
int n, k, ptr, d[20][(1 << 21)];
vector <int> g[N];
vector < pair <int, int> > v[100];
pair <int, int> dfs (int x, int p, int h) {
if (h == k) {
if (h) v[++ptr].push_back ({ptr, h - 1});
return {ptr, ptr};
}
int l = 0, r;
for (int to : g[x]) {
if (to != p) {
auto a = dfs (to, x, h + 1);
if (!l) l = a.first;
r = a.second;
}
}
if (h && l) v[r].push_back ({l, h - 1});
return {l, r};
}
int main () {
cin >> n >> k;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back (b);
g[b].push_back (a);
}
if (k * k >= n) {
cout << "DA";
return 0;
}
dfs (0, -1, 0);
d[0][0] = 1;
for (int i = 1; i <= ptr; i++) {
for (int j = 0; j < (1 << k); j++) {
for (auto a : v[i]) {
if (j & (1 << a.second)) {
d[i][j] |= d[a.first - 1][j ^ (1 << a.second)];
}
}
}
}
for (int j = 0; j < (1 << k); j++)
if (d[ptr][j]) {
cout << "DA";
return 0;
}
cout << "NE";
}
Compilation message
burza.cpp: In function 'std::pair<int, int> dfs(int, int, int)':
burza.cpp:38:14: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
return {l, r};
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
53 ms |
49912 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
99 ms |
61048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
92 ms |
60296 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
49 ms |
48120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
104 ms |
60792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
93 ms |
60512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
78 ms |
59768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
61 ms |
51192 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
56 ms |
49784 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
77 ms |
54648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |