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;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, k, a, b;
cin >> n >> k;
vvi adj(n);
for(int i = 0; i < n - 1; i++){
cin >> a >> b;
adj[--a].emplace_back(--b);
adj[b].emplace_back(a);
}
if(pow(k, 2) >= n){
cout << "DA"; return 0;
}
map<int, int> lost;
vvi cutoff_cover(n), depth_nodes(k + 1);
function<void(int, int, int)> dfs;
dfs = [&](int at, int prev, int depth){
depth_nodes[depth].emplace_back(at);
if(depth == k){
lost[at] = sz(lost);
cutoff_cover[at] = {at};
return;
}
for(int u : adj[at]){
if(u != prev){
dfs(u, at, depth + 1);
cutoff_cover[at].insert(cutoff_cover[at].end(), cutoff_cover[u].begin(), cutoff_cover[u].end());
}
}
};
dfs(0, 0, 0);
vector<pii> intervals;
for(const vi &cc : cutoff_cover){
if(cc.empty())
intervals.emplace_back(-1, -1);
else
intervals.emplace_back(lost[cc.front()] + 1, lost[cc.back()] + 1);
}
vi max_cover(1 << k);
max_cover[0] = 0;
for(int ss = 1; ss < (1 << k); ss++){
int &curr = max_cover[ss];
for(int to_add = 0; to_add < k; to_add++){
if(ss & (1 << to_add)){
int prev = max_cover[ss ^ (1 << to_add)];
for(int u : depth_nodes[to_add + 1])
if(intervals[u].fi <= prev + 1)
curr = max(curr, intervals[u].se);
}
}
if(max_cover[ss] == sz(lost)){
cout << "DA"; return 0;
}
}
cout << "NE";
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... |