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 pb push_back
#define repn(i, a, b) for(int i=a; i < b; ++i)
const int INF = 0x3f3f3f3f;
const int N = 410;
int n, k;
int w[N][N];
vector<int> e[N];
int dfs(int u, int re, int prv = 0) {
if (w[u][re] != -1) return w[u][re];
int &ans = w[u][re];
ans = INF;
if (re == 0) {
if (e[u].size() < 2) return ans = 0;
return ans;
}
if (u == 1) {
if (e[u].size() < 1) return ans = 0;
} else if (e[u].size() < 3) return ans = 0;
multiset < int > ms;
for(auto v: e[u]) if (v != prv)
ms.insert(dfs(v, re -1, u));
for(auto v: e[u]) if (v != prv) {
ms.erase(ms.find(w[v][re-1]));
ans = min(ans, *ms.crbegin() + 1);
ms.insert(w[v][re-1]);
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin >> n >> k;
repn(i, 1, n) {
int u, v;
cin >> u >> v;
e[u].pb(v);
e[v].pb(u);
}
memset(w, -1, sizeof w);
cout << (dfs(1, k) < k ? "DA" : "NE");
}
# | 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... |