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 int int64_t
typedef vector<int> vi;
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define trav(i, a) for (auto& i : a)
const int N = 405;
vi g[N];
int dfs(int u, int p) {
vi x; trav(v, g[u]) if (v != p) x.pb(dfs(v, u));
x.pb(0); x.pb(0); sort(all(x)); reverse(all(x));
return x[1] + 1;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
FOR(i, 0, n - 1) {
int u, v; cin >> u >> v;
g[u].pb(v); g[v].pb(u);
}
cout << (dfs(1, 0) <= k ? "DA" : "NE") << endl;
}
/*
hori san
Claim: If k^2 >= n, then then the answer is yes.
*/
# | 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... |