Submission #974799

#TimeUsernameProblemLanguageResultExecution timeMemory
974799KasymKCat in a tree (BOI17_catinatree)C++17
11 / 100
1018 ms3596 KiB
#include "bits/stdc++.h" using namespace std; const int N = 1e5 + 5; int n, d; int mx = INT_MIN; vector<int> adj[N], bit; int vis[N], dis[N]; int in_yakyn(int id){ for(int i = 0; i < n; ++i) vis[i] = dis[i] = 0; queue<int> q; q.push(id); vis[id] = 1; while(!q.empty()){ int x = q.front(); q.pop(); for(auto i : adj[x]) if(!vis[i]){ vis[i] = 1; q.push(i); dis[i] = dis[x] + 1; if(bit[i]) return dis[i]; } } } bool barla(){ int cnt = count(bit.begin(), bit.end(), 1); if(cnt <= 1) return 1; for(int i = 0; i < n; ++i) if(bit[i] and in_yakyn(i) < d) return 0; return 1; } void f(int x){ if(x == n){ int cnt = count(bit.begin(), bit.end(), 1); if(barla()) mx = max(mx, cnt); return; } for(int i = 0; i <= 1; ++i){ bit[x] = i; f(x + 1); } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> d; for(int i = 1; i <= n - 1; ++i){ int x; cin >> x; adj[x].push_back(i); adj[i].push_back(x); } bit.resize(n); f(0); cout << mx << "\n"; return 0; }

Compilation message (stderr)

catinatree.cpp: In function 'int in_yakyn(int)':
catinatree.cpp:17:16: warning: control reaches end of non-void function [-Wreturn-type]
   17 |     queue<int> q;
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...