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 <iostream>
#include <vector>
using namespace std;
int n, k;
vector <vector <int>> adj;
bool solve(int s, int p, int d) {
if (d == k+1)
return false;
if (adj[s].size() == 1 && s != p)
return true;
for (auto i : adj[s]) {
if (i == p)
continue;
bool ans = true;
for (auto j : adj[s]) {
if (j == p || j == i)
continue;
ans &= solve(j, s, d+1);
}
if (ans)
return true;
}
return false;
}
int main() {
cin >> n >> k;
adj.resize(n+1);
for (int i = 0; i < n-1; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
if (solve(1, 1, 0))
cout << "DA\n";
else
cout << "NE\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... |