이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//https://oj.uz/problem/view/COCI16_burza
#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
const int MAX_N = 400 + 5;
int dp[MAX_N][MAX_N][2];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
vector <vector <int>> graph(n + 1);
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
vector <int> parent(n + 1);
auto DFS = [&] (auto DFS, int u) -> void {
int leaf = true;
for (int v : graph[u]) {
if (v == parent[u]) continue;
parent[v] = u;
leaf = false;
DFS(DFS, v);
}
if (leaf) {
for (int i = 1; i <= k; ++i) dp[u][i][1] = true;
dp[u][0][0] = true;
return;
}
dp[u][0][0] = true;
for (int plays = 1; plays <= k; ++plays) {
dp[u][plays][0] = true;
dp[u][plays][1] = true;
for (int v : graph[u]) {
if (v == parent[u]) continue;
dp[u][plays][1] &= not dp[v][plays - 1][0];
int current = false;
for (int t : graph[u]) {
if (v == t or t == parent[u]) continue;
current |= not dp[t][plays][1];
}
dp[u][plays][0] &= current;
}
}
// cerr << "DEBUG: " << u << '\n';
// for (int plays = 0; plays <= k; ++plays) cerr << dp[u][plays][0] << ' ' << dp[u][plays][1] << '\n';
};
DFS(DFS, 1);
int ans = dp[1][k][1];
cout << (ans ? "DA" : "NE");
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... |