// 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++;
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);
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 - 1])
{
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
82828 KB |
Output is correct |
2 |
Correct |
222 ms |
105876 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
47 ms |
101356 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
100744 KB |
Output is correct |
2 |
Correct |
247 ms |
101060 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
219 ms |
102384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
101968 KB |
Output is correct |
2 |
Correct |
233 ms |
101968 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
39 ms |
82348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
99504 KB |
Output is correct |
2 |
Correct |
223 ms |
105820 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Incorrect |
33 ms |
70860 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
97432 KB |
Output is correct |
2 |
Correct |
216 ms |
100664 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
48 ms |
101660 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
101444 KB |
Output is correct |
2 |
Correct |
215 ms |
99884 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
43 ms |
94044 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
103268 KB |
Output is correct |
2 |
Correct |
216 ms |
100292 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
218 ms |
100604 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
89204 KB |
Output is correct |
2 |
Correct |
220 ms |
103720 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
30 ms |
63940 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
74256 KB |
Output is correct |
2 |
Correct |
221 ms |
104836 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
30 ms |
64316 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
88144 KB |
Output is correct |
2 |
Correct |
235 ms |
104576 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
133 ms |
89152 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |