제출 #951351

#제출 시각아이디문제언어결과실행 시간메모리
951351BF001Burza (COCI16_burza)C++17
0 / 160
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define N 405 int n, k, rt[N]; vector<int> adj[N]; int get(int u, int p){ if (rt[u] != -1) return rt[u]; vector<int> pre(adj[u].size() + 2, 0); vector<int> suf(adj[u].size() + 2, 0); int pos = 0; int r = n; if (adj[u].size() == 1 && p != 0) r = 1; if (adj[u].size() == 0) r = 0; for (auto x : adj[u]){ if (x == p) continue; pos++; pre[pos] = max(pre[pos - 1], get(x, u) + 1); } pos++; for (int i = adj[u].size() - 1; i >= 0; i--){ int x = adj[u][i]; if (x == p) continue; pos--; suf[pos] = max(suf[pos + 1], get(x, u) + 1); } pos = 0; for (auto x : adj[u]){ if (x == p) continue; pos++; int du = max(pre[pos - 1], suf[pos + 1]); r = min(r, du); } return rt[u] = r; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); memset(rt, -1, sizeof(rt)); cin >> n >> k; for (int i = 1; i <= n - 1; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } if (get(1, 0) <= k){ cout << "DA"; } else cout << "NE"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...