#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int n,k;
vector<vector<int> > dp,graf;
vector<vector<pair<int,int> > > nxt;
vector<int> in;
int t=0;
void init(int tr,int par,int d)
{
in[tr]=t;
if(d==k)
t++;
if(d!=k)
for(auto p:graf[tr])
{
if(p==par)
continue;
init(p,tr,d+1);
}
if(t>in[tr]&&d!=0)
nxt[in[tr]].pb({t,d-1});
}
bool calc(int mask,int tr)
{
if(tr==t)
return true;
if(dp[mask][tr]!=-1)
return dp[mask][tr];
for(auto p:nxt[tr])
if((mask&(1<<p.s))==0)
if(calc(mask|(1<<p.s),p.f))
return dp[mask][tr]=1;
return dp[mask][tr]=0;
}
int main()
{
scanf("%i %i",&n,&k);
graf.resize(n);in.resize(n);nxt.resize(n);
for(int i=1;i<n;i++)
{
int a,b;
scanf("%i %i",&a,&b);
a--;b--;
graf[a].pb(b);
graf[b].pb(a);
}
if(k*(k+1)+1>n)
{
printf("DA\n");
return 0;
}
init(0,-1,0);
dp.resize(1<<k,vector<int>(t+1,0));
for(int i=0;i<1<<k;i++)
dp[i][t]=1;
for(int i=t-1;i>=0;i--)
{
for(int j=(1<<k)-1;j>=0;j--)
{
for(auto p:nxt[i])
{
if((1<<p.s&j)==0)
if(dp[j&1<<p.s][p.f])
{
dp[j][i]=1;
break;
}
}
}
}
if(dp[0][0])
printf("DA\n");
else
printf("NE\n");
return 0;
}
Compilation message
burza.cpp: In function 'bool calc(int, int)':
burza.cpp:56:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
return dp[mask][tr]=1;
burza.cpp:57:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
return dp[mask][tr]=0;
burza.cpp: In function 'int main()':
burza.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&n,&k);
~~~~~^~~~~~~~~~~~~~~
burza.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&a,&b);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
7168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
184 ms |
46584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
182 ms |
46596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
17664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
148 ms |
40540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
151 ms |
48636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
146 ms |
48636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
13568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
5632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
18504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |