This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
vi s_graph[401], graph[401];
int n, k, md[401], p[401];
void dfs(int u, int d) {
md[u] = d;
if (d < k) trav(v, s_graph[u]) if (p[u] != v) {
p[v] = u;
dfs(v, d + 1);
md[u] = max(md[u], md[v]);
if (md[v] == k) graph[u].pb(v);
}
}
vector<bitset<401>>dp(int u, int d) {
vector<bitset<401>> sols;
if(sz(graph[u]))sols.pb(bitset<401>());
trav(v, graph[u]) if (v != p[u]) {
vector<bitset<401>> vec = dp(v, d + 1);
vector<bitset<401>> nxt;
trav(sol, sols) trav(bs, vec) if (!(sol & bs).count())nxt.pb(sol|bs);
sols.swap(nxt);
}
bitset<401> bs;
bs[d]=1;
sols.pb(bs);
//cout<<"u = "<<u<<" d = "<<d<<" num sol = "<<sz(sols)<<endl;
return sols;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> n >> k;
rep(i, 0, n - 1) {
int u, v;
cin >> u >> v;
s_graph[--u].pb(--v);
s_graph[v].pb(u);
}
p[0] = 0;
dfs(0, 0);
if(sz(dp(0,0))<=1)cout<<"NE"<<endl;
else cout<<"DA"<<endl;
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... |