이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |