#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define vi vector<ll>
#define vii vector<vi>
#define pl pair<ll, ll>
#define all(X) X.begin(),X.end()
#define vp vector<pl>
#define mi map<ll,ll>
#define ld long double
#define vc vector<char>
#define vcc vector<vc>
#define mc map<char,int>
#define sortx(X) sort(X.begin(),X.end());
#define allr(X) X.rbegin(),X.rend()
#define ln '\n'
#define YES {cout << "YES\n"; return;}
#define NO {cout << "NO\n"; return;}
#define MUN {cout << "-1\n"; return;}
using namespace std;
const int MODE = 998244353;
bool req(vii &adj, ll n, ll p, ll lvl, ll k) {
if (lvl >= k) return 0;
ll cnt = 0;
for (auto neg : adj[n]) if (neg != p) {
ll re = req(adj, neg, n, lvl+1, k);
cnt += (re == 0);
}
return cnt <= 1;
}
void solve(ll tc) {
ll n, k;
cin >> n >> k;
vii adj(n + 1);
for (int i = 0; i < n-1; i++)
{
ll u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if (req(adj, 1, 0, 0, k)) cout << "DA\n";
else cout << "NE\n";
}
int32_t main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int size = 1;
// freopen("disrupt.in", "r", stdin );
// freopen("disrupt.out", "w", stdout);
// cin >> size;
for (int tc = 1; tc <= size; tc++){
solve(tc);
// if (tc != size) cout << '\n';
}
}
# | 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... |