제출 #951535

#제출 시각아이디문제언어결과실행 시간메모리
951535BF001Burza (COCI16_burza)C++17
0 / 160
1 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define N 405 int n, k, rt[N]; vector<int> adj[N]; vector<int> pre[N], suf[N]; int get(int u, int p){ if (rt[u] != -1) return rt[u]; int pos = 0; int r = 1e18; if (adj[u].size() == 1 && p != 0) r = 1; if (adj[u].size() == 0) r = 1; pre[u][0] = 1; for (auto x : adj[u]){ if (x == p) continue; pos++; pre[u][pos] = max(pre[u][pos - 1], get(x, u) + 1); } pos++; suf[u][pos] = 1; for (int i = adj[u].size() - 1; i >= 0; i--){ int x = adj[u][i]; if (x == p) continue; pos--; suf[u][pos] = max(suf[u][pos + 1], get(x, u) + 1); } pos = 0; for (auto x : adj[u]){ if (x == p) continue; pos++; int du = max(pre[u][pos - 1], suf[u][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); } for (int i = 0; i <= n; i++) { pre[i].resize(adj[i].size() + 2, 0); suf[i].resize(adj[i].size() + 2, 0); } 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...