Submission #782384

#TimeUsernameProblemLanguageResultExecution timeMemory
782384vgoofficialBurza (COCI16_burza)C++14
160 / 160
357 ms15564 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int n,k; vector<vector<int>> edges; vector<int> depth; vector<int> parents; vector<vector<int>> depths(400); int maxDepth(int i, int dpth) { depth[i]=dpth; int maxD = dpth; for(int j = 0; j < edges[i].size(); j++) { int l = edges[i][j]; if(depth[l]!=-1) continue; if(dpth==k) { edges[i][j]=-1; } else { if(maxDepth(l, dpth+1)!=k) { edges[i][j]=-1; } else { parents[l]=i; maxD=k; } } } if(maxD==k) { depths[dpth].push_back(i); } return maxD; } struct state { int level; vector<int> mustConsider; state(int level, vector<int> unaccessible) { this->mustConsider = unaccessible; this->level = level; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; if(k * k>n) { cout << "DA" << endl; return 0; } edges=vector<vector<int>>(n); depth=vector<int>(n, -1); parents=vector<int>(n, -1); depth[0]=0; for(int i = 1; i < n; i++) { int a,b; cin >> a >> b; edges[a-1].push_back(b-1); edges[b-1].push_back(a-1); } maxDepth(0, 0); /* for(int i = 0; i < n; i++) { cout << i << " " << depth[i] << " " << parents[i] << endl; for(int j: depths[i]) { cout << j << " "; } cout << endl; for(int j: edges[i]) { cout << j << " "; } cout << endl; } */ deque<vector<int>> q; q.push_back(vector<int>(1,0)); set<vector<int>> vis; while(q.size()) { vector<int> s = q.front(); q.pop_front(); if(s.size()==0) { cout << "DA" << endl; return 0; } int remain = k-depth[s[0]]; vector<int> next; for(int i: s) { for(int j: edges[i]) { if(j==-1) continue; if(j==parents[i]) continue; next.push_back(j); } } if(next.size()>remain) { continue; } for(int i = 0; i < next.size(); i++) { swap(next[i], next.back()); vector<int> temp = next; temp.pop_back(); sort(begin(temp), end(temp)); if(!vis.count(temp)) { q.push_back(temp); vis.insert(temp); } swap(next[i], next.back()); } } cout << "NE" << endl; }

Compilation message (stderr)

burza.cpp: In function 'int maxDepth(int, int)':
burza.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int j = 0; j < edges[i].size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~~~
burza.cpp: In function 'int main()':
burza.cpp:91:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |         if(next.size()>remain) {
      |            ~~~~~~~~~~~^~~~~~~
burza.cpp:94:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int i = 0; i < next.size(); i++) {
      |                        ~~^~~~~~~~~~~~~
#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...