제출 #589487

#제출 시각아이디문제언어결과실행 시간메모리
589487BhavayGoyalBurza (COCI16_burza)C++14
0 / 160
1119 ms524288 KiB
#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); } 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(); if (k >= 20) { cout << "DA" << endl; return; } 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 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...