Submission #105952

#TimeUsernameProblemLanguageResultExecution timeMemory
105952nikolapesic2802Burza (COCI16_burza)C++14
160 / 160
100 ms54836 KiB
#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)); if(calc(0,0)) printf("DA\n"); else printf("NE\n"); return 0; }

Compilation message (stderr)

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);
         ~~~~~^~~~~~~~~~~~~~~
#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...