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>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define sep ' '
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define kill(x) {cout << x << endl;return;}
const int N = 500;
const ll LLINF = 2e18;
int n, k;
int h[N];
int par[N];
int cnt[N];
vi adj[N];
// check MAXN
// diffrence between extract and erase in multi set
void set_io() {
fastIO;
// freopen("guard.in", "r", stdin);
// freopen("guard.out", "w", stdout);
}
void dfs(int v = 0, int p = -1) {
h[v] = (p == -1 ? 0 : h[p] + 1);
par[v] = p;
for(int neigh: adj[v]) {
if (neigh == p) continue;
dfs(neigh, v);
cnt[v] += cnt[neigh];
}
cnt[v] += (h[v] == k);
}
void solve() {
cin >> n >> k;
for(int i = 0, a, b ; i < n-1 ; i ++)
cin >> a >> b,
adj[--a].pb(--b), adj[b].pb(a);
dfs();
set<pair<int, int>> p, q;
q.insert({cnt[0], 0});
int ans = 0;
while(true) {
p.clear();
for(auto [x, u]: q) {
// cout << u+1 << endl;
if (h[u] == k) {
cout << "NE" << endl;
return;
}
for(int neigh: adj[u])
if (neigh != par[u])
p.insert({adj[neigh].size(), neigh});
}
if (p.size() == 0) break;
p.erase(*p.rbegin());
ans++;
swap(p, q);
}
cout << (ans <= k ? "DA" : "NE") << endl;
}
int main() {
set_io();
solve();
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... |