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;
int n, k;
vector <int> adj[405];
int dp[405]; /// dp[i] = nr minim de mutari daca avem coin-ul in i
void DFS(int nod, int father) {
int maxim1 = 0, maxim2 = 0;
for (int i : adj[nod]) {
if (i != father)
DFS(i, nod);
if (dp[i] > maxim1) {
maxim2 = maxim1;
maxim1 = dp[i];
}
else if (dp[i] > maxim2) {
maxim2 = maxim1;
maxim1 = dp[i];
}
}
if (nod != 1 && adj[nod].size() <= 2)
dp[nod] = 0;
else dp[nod] = maxim2 + 1;
}
int main()
{
cin >> n >> k;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
DFS(1, 0);
if (dp[1] < k)
cout << "DA\n";
else cout << "NE\n";
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... |