제출 #394510

#제출 시각아이디문제언어결과실행 시간메모리
394510sinamhdvBurza (COCI16_burza)C++11
160 / 160
292 ms105868 KiB
// COCI16_burza #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1e9 + 100; const ll LINF = 1e18 + 100; #ifdef DEBUG #define dbg(x) cout << #x << " = " << (x) << endl << flush; #define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; } #else #define dbg(x) ; #define dbgr(s, f) ; #endif #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define fr first #define sc second #define endl '\n' #define MAXN 420 #define MAXK 21 int n, k; vector<int> adj[MAXN]; vector<bool> dp[MAXN]; vector<int> vec[MAXN]; vector<int> leaf; int h[MAXN]; int sttime[MAXN], fntime[MAXN], timer; void dfs(int v, int par) { sttime[v] = timer; if (h[v] == k) { timer++; fntime[v] = timer; vec[fntime[v]].pb(v); return; } for (int u : adj[v]) { if (u == par) continue; h[u] = h[v] + 1; dfs(u, v); } fntime[v] = timer; if (sttime[v] != fntime[v]) vec[fntime[v]].pb(v); } int32_t main(void) { fast_io; cin >> n >> k; FOR(i, 0, n - 1) { int x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } if (n <= k * k) return cout << "DA\n", 0; dfs(1, -1); FOR(i, 0, n + 5) dp[i].resize(1 << MAXK); dbgr(sttime + 1, sttime + n + 1); dbgr(fntime + 1, fntime + n + 1); FOR(mask, 0, 1 << k) dp[0][mask] = true; FOR(i, 1, fntime[1] + 1) { FOR(mask, 0, 1 << k) { for (int u : vec[i]) { if (!(mask >> (h[u] - 1) & 1)) continue; int nmask = mask ^ (1 << (h[u] - 1)); dp[i][mask] = (dp[i][mask] || dp[sttime[u]][nmask]); } } } if (dp[fntime[1]][(1 << k) - 1]) cout << "DA\n"; else cout << "NE\n"; 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...