# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1275521 | chanhchuong123 | Burza (COCI16_burza) | C++20 | 33 ms | 868 KiB |
#include<bits/stdc++.h>
using namespace std;
const bool multiTest = false;
#define task "C"
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
template<typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) a = b; else return 0; return 1;
}
template<typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) a = b; else return 0; return 1;
}
const int MAX = 404;
int n, k;
int ll[MAX];
int rr[MAX];
int dp[1 << 20];
vector<int> leaves;
vector<int> adj[MAX];
vector<int> nodes[MAX];
void dfs(int u, int p, int depth) {
nodes[depth].push_back(u);
ll[u] = n + 1;
rr[u] = 0 + 0;
if (depth == k) {
ll[u] = rr[u] = leaves.size() + 1;
leaves.push_back(u);
return;
}
for (int v: adj[u]) if (v != p) {
dfs(v, u, depth + 1);
minimize(ll[u], ll[v]);
maximize(rr[u], rr[v]);
}
}
void process(void) {
cin >> n >> k;
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if (k * k >= n) {
cout << "DA";
return;
}
dfs(1, -1, 0);
for (int mask = 0; mask < (1 << k); ++mask) {
for (int i = 0; i < k; ++i) if (!(mask >> i & 1)) {
for (int u: nodes[i + 1]) if (ll[u] <= dp[mask] + 1) {
maximize(dp[mask | (1 << i)], rr[u]);
}
}
}
if (dp[(1 << k) - 1] == leaves.size()) {
cout << "DA";
return;
}
cout << "NE";
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int nTest = 1; if (multiTest) cin >> nTest;
while (nTest--) {
process();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |