Submission #974470

#TimeUsernameProblemLanguageResultExecution timeMemory
974470KasymKCat in a tree (BOI17_catinatree)C++17
11 / 100
1066 ms3920 KiB
#include "bits/stdc++.h" using namespace std; const int N = 1e5 + 5; vector<int> adj[N], vis; int n, d; int mx = INT_MIN; int marked[N], dis[N], vis1[N]; int poz = 0; int in_yakyn (int x) { // if (poz) { // cout <<"--> " << x; // exit(0); // } queue <int> q; for (int i = 0; i < n; ++i) vis1[i] = dis[i] = 0; q.push(x); vis1[x] = 1; while (!q.empty()) { int to = q.front(); // if (poz == 1) { // cout << "ll-> " << to << "\n"; // } q.pop(); for (int i : adj[to]) { if (vis1[i]) continue; dis[i] = dis[to] + 1; q.push(i); vis1[i] = 1; if (vis[i]) { // if (poz) { // cout << " men " << i << " " << x << " " << dis[i] << "\n"; //// exit(0); // // } return dis[i]; } } } assert (1 == -1); } bool barla() { int cnt = count(vis.begin(), vis.end(), 1); if(cnt <= 1) return true; if (vis[0] == 0 and vis[1] == 0 and vis[2] == 1 and vis[3] == 1) { poz = 1; // cout << " kk --> " << in_yakyn (3); // << " " << in_yakyn (2); // exit(0); } for (int i = 0; i < n; ++i) { if (vis[i]) { if (in_yakyn(i) < d) return 0; } } return 1; } int sana () { int ret = 0; for (int i = 0; i < n; ++i) { if (vis[i]) ret++; } return ret; } void f(int x){ if(x == n){ if(barla()) mx = max(mx, sana()); return; } for(int i = 0; i <= 1; ++i){ vis[x] = i; f(x + 1); } } int main() { // freopen ("input.txt", "r", stdin); scanf("%d%d", &n, &d); for(int i = 1; i <= n - 1; ++i) { int a; scanf("%d", &a); adj[a].push_back(i); adj[i].push_back(a); } vis.resize(n); f(0); printf("%d\n", mx); return 0; }

Compilation message (stderr)

catinatree.cpp: In function 'int main()':
catinatree.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |     scanf("%d%d", &n, &d);
      |     ~~~~~^~~~~~~~~~~~~~~~
catinatree.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...