#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll D[402] = {0}, m;
ll S[402] = {0};
vector < ll > adj[402];
void Go(ll node, ll par) {
for ( ll chi : adj[node]) {
if ( chi == par) continue;
D[chi] = D[node] + 1;
if ( D[chi] == m) S[chi] = 1;
Go(chi, node);
S[node] += S[chi];
}
}
ll mx_node, mx_sz;
bool DFS(ll node, ll par) {
if (D[node] > m) return true;
if ( D[node] == m) return false;
mx_node= mx_sz = 0;
for ( ll chi : adj[node]) {
if ( chi == par) continue;
if ( S[chi] >= mx_sz) {
mx_sz = S[chi];
mx_node = chi;
}
}
for ( ll chi : adj[node]) {
if ( chi == par || chi == mx_node) continue;
if ( DFS(chi, node) == false) return false;
}
return true;
}
int main() {
ll n, r, x, y, i, j, ans, t;
cin >> n >> m;
for (i = 1; i < n; i ++) {
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
Go(1, 1);
if ( DFS(1, 1)) cout << "NE" << endl;
else cout << "DA" << endl;
}
# | 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... |