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>
#define PB push_back
#define i2 array<int,2>
using namespace std;
const int N = 410;
const int PW = (1 << 20);
vector<int> g[N];
vector<i2> qr[N];
bitset<PW> dp[N];
int cnt, h[N], sta[N], ed[N], n, k;
void dfs(int v, int p){
if (h[v] == k - 1){
sta[v] = cnt++;
ed[v] = cnt;
qr[sta[v]].PB({v, ed[v]});
return;
}
sta[v] = cnt;
for (int u : g[v]){
if (u == p) continue;
h[u] = h[v] + 1;
dfs(u, v);
}
if (v > 0) {
ed[v] = cnt;
qr[sta[v]].PB({v, ed[v]});
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> k;
if (k * k >= n){
cout << "DA";
return 0;
}
for (int i = 1; i < n; i++){
int x, y; cin >> x >> y;
x--; y--;
g[x].PB(y);
g[y].PB(x);
}
h[0] = -1;
dfs(0, -1);
dp[0][0] = 1;
for (int i = 0; i < cnt; i++)
for (int msk = 0; msk < (1 << k); msk++){
if (!dp[i][msk]) continue;
for (i2 cr : qr[i]) {
int v = cr[0];
int j = cr[1];
if (!(msk & (1 << h[v])))
dp[j][msk + (1 << h[v])] = 1;
}
}
for (int msk = 0; msk < (1 << k); msk++)
if (dp[cnt][msk]) {
cout << "DA";
return 0;
}
cout << "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... |