Submission #865025

#TimeUsernameProblemLanguageResultExecution timeMemory
865025maks007Cat in a tree (BOI17_catinatree)C++14
0 / 100
1 ms344 KiB
// Bismi ALlah #include "bits/stdc++.h" using namespace std; signed main () { int n, d; cin >> n >> d; vector <int> g[n]; function <int(int,int,int, int)> get=[&](int v, const int & target, int p, int dist) { if(target == v) return dist; int f = -1; for(auto u : g[v]) { if(u == p) continue; f = max(f, get(u, target, v, dist + 1)); } return f; }; for(int i = 1; i < n; i ++) { int p; cin >> p; g[i].push_back(p); g[p].push_back(i); } int ans = 0; for(int mask = 0; mask < (1 << n); mask ++) { vector <int> v; for(int i= 0; i < n; i ++) { if(mask & (1 << i)) v.push_back(i); } for(int i = 1; i < v.size(); i ++) { if(get(v[i-1], v[i], -1, 0) >= d) continue; goto end; } // cout << mask << " "; ans = max(ans, __builtin_popcount(mask)); end:; } cout << ans; return 0; }

Compilation message (stderr)

catinatree.cpp: In function 'int main()':
catinatree.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 1; i < v.size(); i ++) {
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...