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;
void solve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1; // cin >> t;
while(t--) {
solve();
}
return 0;
}
int n, k;
const int MXN = 400;
vector<int> edges[MXN];
bool dfs(int i, int parent, int depth) {
if (depth >= k) return false;
bool alreadyChildFalse = false;
for (int v : edges[i]) {
if (v == parent) continue;
if (dfs(v, i, depth+1)) continue;
if (alreadyChildFalse) return false;
alreadyChildFalse = true;
}
return true;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n - 1; i++) {
int x, y; cin >> x >> y;
x--;
y--;
edges[x].push_back(y);
edges[y].push_back(x);
}
if (dfs(0, -1, 0)) {
cout << "DA" << endl;
} else {
cout << "NE" << 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... |