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;
#define LL long long
#define pb push_back
/* Date: 9/8/21
* Link: https://oj.uz/problem/view/COCI16_burza
* Verdict:
*/
vector<int> alive(405);
vector<int> adj[405];
vector<int> depth(405);
vector<int> par(405);
int N, K;
void dfs(int p = -1, int c = 0) {
par[c] = p;
if (depth[c] == K) {
alive[c] = 1;
return;
}
for (int to : adj[c]) {
if (to == p) continue;
depth[to] = depth[c]+1;
dfs(c, to);
alive[c] += alive[to];
}
}
int main() {
ios::sync_with_stdio(0);
cin >> N >> K;
if (K >= 25) {
cout << "DA" << endl;
return 0;
}
fill(alive.begin(), alive.end(), 0);
for (int i = 0; i < N-1; i++) {
int a, b;
cin >> a >> b;
a--; b--;
adj[a].pb(b); adj[b].pb(a);
}
depth[0] = 0;
dfs();
int idx = 0, nidx = 1;
vector<int> thing[2];
thing[0].pb(0);
int step = 0;
while(!thing[idx].empty()) {
int best = -1, bestalive = -1;
for (int node : thing[idx]) {
for (int op : adj[node]) {
if (op == par[node]) continue;
if (alive[op] > bestalive) {
best = op; bestalive = alive[op];
}
}
}
for (int node : thing[idx]) {
for (int op : adj[node]) {
if (op != par[node] && op != best) {
thing[nidx].pb(op);
}
}
}
thing[idx].clear();
idx = nidx;
nidx = 1 ^ nidx;
step++;
}
if (step > K) {
cout << "NE" << endl;
}
else {
cout << "DA" << endl;
}
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... |