# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
589488 |
2022-07-04T19:04:18 Z |
BhavayGoyal |
Burza (COCI16_burza) |
C++14 |
|
214 ms |
210044 KB |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
// -------------------------------------------------- Main Code --------------------------------------------------
const int N = 401;
vi g[N];
int n, k, ct = 0, depth[N], Left[N], Right[N], dp[N][(1<<20)];
void dfs(int src = 0, int par = -1) {
Left[src] = inf;
Right[src] = -inf;
if (depth[src] == k) {
Left[src] = ++ct;
Right[src] = ct;
}
for (auto ch : g[src]) {
if (ch == par) continue;
depth[ch] = depth[src]+1;
dfs(ch, src);
Left[src] = min(Left[src], Left[ch]);
Right[src] = max(Right[src], Right[ch]);
}
}
void dfs1(int src = 0, int par = -1) {
if (depth[src] > k) return;
for (auto ch : g[src]) {
if (ch == par) continue;
dfs1(ch, src);
}
if (src == 0 || Left[src] == inf) return;
int d = depth[src]-1;
for (int mask = 0; mask < (1<<k); mask++) {
if (mask&(1<<d)) {
dp[Right[src]][mask] = max(dp[Right[src]][mask], dp[Left[src]-1][mask^(1<<d)] + Right[src]-Left[src]+1);
}
}
}
void sol() {
cin >> n >> k;
for (int i = 0; i < n-1; i++) {
int a, b; cin >> a >> b;
g[--a].pb(--b);
g[b].pb(a);
}
if (k >= 20) {
cout << "DA" << endl;
return;
}
dfs();
for (int i = 0; i < n; i++) for (int j = 0; j < (1<<k); j++) dp[i][j] = -inf;
dp[0][0] = 0;
dfs1();
for (int i = 0; i < (1<<k); i++) {
if (dp[ct][i] == ct) {
cout << "DA" << endl;
return;
}
}
cout << "NE" << endl;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
sol();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
22740 KB |
Output is correct |
2 |
Correct |
192 ms |
210044 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
199428 KB |
Output is correct |
2 |
Correct |
200 ms |
200396 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
201 ms |
203048 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
202072 KB |
Output is correct |
2 |
Correct |
195 ms |
202076 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
2772 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
51420 KB |
Output is correct |
2 |
Correct |
214 ms |
209928 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
2388 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
193144 KB |
Output is correct |
2 |
Correct |
207 ms |
199356 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
200992 KB |
Output is correct |
2 |
Correct |
187 ms |
197884 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
2 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
204584 KB |
Output is correct |
2 |
Correct |
195 ms |
198888 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
197 ms |
199400 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
45992 KB |
Output is correct |
2 |
Correct |
206 ms |
205736 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
2132 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
20308 KB |
Output is correct |
2 |
Correct |
190 ms |
207840 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
89296 KB |
Output is correct |
2 |
Correct |
204 ms |
207316 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
86 ms |
90384 KB |
Output is correct |
6 |
Correct |
2 ms |
1620 KB |
Output is correct |