#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> intervalL;
vector<int> intervalR;
vector<int> depth;
vector<vector<int>> adjList;
vector<vector<int>> check;
int track = 0;
void dfs(int node, int parent){
if (depth[node] == k){
intervalL[node] = track;
intervalR[node] = track;
track++;
}
else{
for (int child : adjList[node]){
if (child == parent) continue;
depth[child] = depth[node]+1;
dfs(child, node);
intervalL[node] = min(intervalL[child], intervalL[node]);
intervalR[node] = max(intervalR[child], intervalR[node]);
}
}
if (node != 0 and intervalR[node] != -1){
check[intervalR[node]].push_back(node);
}
}
int main(){
cin >> n >> k;
adjList.resize(n);
depth.resize(n);
intervalL.resize(n);
intervalR.resize(n);
check.resize(n);
depth[0] = 0;
fill(intervalL.begin(), intervalL.end(), 1000000007);
fill(intervalR.begin(), intervalR.end(), -1);
for (int i = 0; i < n-1; i++){
int a, b;
cin >> a >> b;
adjList[a-1].push_back(b-1);
adjList[b-1].push_back(a-1);
}
if (k*k >= n){
cout<<"DA";
return 0;
}
dfs(0, 0);
bool valid = false;
//dp[i][j] - can we use only nodes of depths in subset i such
//that we cannot get to the first j(0 index) nodes at depth K
bool dp[(1<<k)][track];
memset(dp, false, sizeof(dp));
for (int i = 1; i < (1<<k); i++){
//can we fill interval [1, j]
for (int j = 0; j < track; j++){
//go through all points going to j
for (int node : check[j]){
//make sure depth is in subset
if ((i&((1<<depth[node])-1)) != 0){
dp[i][j] = dp[i][j] or (dp[i^(1<<depth[node])][intervalL[node]]);
}
}
}
if (dp[i][track-1])
valid = true;
}
if (valid)
cout<<"DA";
else
cout<<"NE";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
3532 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
17 ms |
21480 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
17 ms |
21192 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
8524 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
18124 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
22476 KB |
Execution killed with signal 7 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
21712 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
6348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
2636 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
8400 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |