#include <iostream>
#include <vector>
using namespace std;
const int N = 405;
int n, k;
int target = 2;
bool rFull = false;
vector<int> h, depths;
vector<bool> rootChildren;
vector<vector<int>> tmpadj, adj;
bool dfs(int node, int parent, int depth, int orgNode) {
depth++;
depths[node] = depth;
if (h[node] == k) {
rootChildren[orgNode] = true;
return true;
}
bool res = false;
for (int v : tmpadj[node]) if (v != parent) {
if (node == 1) {
orgNode = v;
}
h[v] = h[node] + 1;
int nxt = dfs(v, node, depth, orgNode);
res |= nxt;
if (nxt) adj[node].push_back(v);
}
return res;
}
void dfs2(int node, int parent) {
if (depths[node] == target) {
target++;
return;
}
if (depths[node] == k + 1 && target == k + 2) {
cout << "NE";
rFull = true;
return;
}
for (int v : adj[node]) {
if (node == 1 && !rootChildren[v]) {
continue;
}
dfs2(v, node);
if (rFull) {
return;
}
}
return;
}
int main()
{
cin >> n >> k;
if (k > 20) {
cout << "DA";
}
h.resize(n + 1);
adj.resize(n + 1);
tmpadj.resize(n + 1);
depths.resize(n + 1, 0);
rootChildren.resize(n + 1);
for (int i = 1; i < n; i++) {
int u, v; cin >> u >> v;
tmpadj[u].push_back(v);
tmpadj[v].push_back(u);
}
if (!dfs(1, -1, 0, 0)) {
cout << "DA";
}
dfs2(1, -1);
if (!rFull) {
cout << "DA";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |