# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
851293 |
2023-09-19T12:02:05 Z |
c2zi6 |
Burza (COCI16_burza) |
C++14 |
|
353 ms |
12636 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int n, k;
vector<vector<int>> gp;
vector<int> d;
vector<bool> lav;
vector<int> l, r;
int last;
void dfs(int u = 0, int p = -1) {
if (p == -1) d[u] = 0;
else d[u] = d[p] + 1;
if (d[u] == k) {
lav[u] = true;
l[u] = last;
r[u] = last;
last++;
return;
}
for (int v : gp[u]) {
if (v == p) continue;
dfs(v, u);
lav[u] = (lav[u] | lav[v]);
r[u] = max(r[u], r[v]);
l[u] = min(l[u], l[v]);
}
}
void solve() {
cin >> n >> k;
gp = vector<vector<int>>(n);
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
u--, v--;
gp[u].push_back(v);
gp[v].push_back(u);
}
if (k > 20) {
cout << "DA" << endl;
return;
}
d = vector<int>(n);
l = vector<int>(n, 2e9);
r = vector<int>(n, -2e9);
lav = vector<bool>(n);
last = 0;
dfs();
// for (int i = 0; i < n; i++) {
// if (!lav[i]) continue;
// cout << i+1 << " " << l[i] << "-" << r[i] << endl;
// }
// cout << "VERJ" << endl;
int lbyr[k][last];
for (int i = 0; i < k; i++) {
for (int j = 0; j < last; j++) {
lbyr[i][j] = -1;
}
}
for (int i = 1; i < n; i++) {
if (!lav[i]) continue;
lbyr[d[i]-1][r[i]] = l[i];
}
bool ans = false;
bool dp[1<<k][last]{};
for (int s = 1; s < (1<<k); s++) {
for (int i = 0; i < last; i++) {
dp[s][i] = false;
for (int j = 0; j < k; j++) {
if (!(s & (1<<j))) continue;
if (lbyr[j][i] == -1) continue;
if (lbyr[j][i] == 0) {
dp[s][i] = true;
break;
}
if (dp[s^(1<<j)][lbyr[j][i]-1]) {
dp[s][i] = true;
break;
}
}
if (dp[s][i] && i == last-1) {
ans = true;
}
}
}
if (ans) cout << "DA" << endl;
else cout << "NE" << endl;
}
int main() {
int t = 1;
//cin >> t;
while (t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
1952 KB |
Output is correct |
2 |
Correct |
353 ms |
12380 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
10844 KB |
Output is correct |
2 |
Correct |
318 ms |
10432 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
323 ms |
10588 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
10588 KB |
Output is correct |
2 |
Correct |
317 ms |
10584 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
4412 KB |
Output is correct |
2 |
Correct |
343 ms |
12636 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
9152 KB |
Output is correct |
2 |
Correct |
311 ms |
10072 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
322 ms |
11356 KB |
Output is correct |
2 |
Correct |
303 ms |
9924 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
10964 KB |
Output is correct |
2 |
Correct |
311 ms |
10308 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
306 ms |
9672 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
3416 KB |
Output is correct |
2 |
Correct |
339 ms |
11728 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
1568 KB |
Output is correct |
2 |
Correct |
340 ms |
11864 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
4344 KB |
Output is correct |
2 |
Correct |
336 ms |
11984 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
133 ms |
4604 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |