Submission #1215768

#TimeUsernameProblemLanguageResultExecution timeMemory
1215768badge881Cat in a tree (BOI17_catinatree)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; int n, d; vector<vector<int>> adj; pii dfs(int u) { pii ans = {1, 0}; for (auto v : adj[u]) { pii ch = dfs(v); ans.first += ch.first; if (ans.second + ch.second + 1 < d) { ans = {ans.first - 1, max(ans.second, ch.second + 1)}; } else ans.second = min(ans.second, ch.second + 1); } return ans; } int main() { scanf("%lld %lld", &n, &d); adj.assign(n + 1, vector<int>()); for (int i = 1; i < n; ++i) { int a; scanf("%lld", &a); adj[a].push_back(i); } printf("%lld\n", dfs(0).first); return 0; }

Compilation message (stderr)

catinatree.cpp: In function 'int main()':
catinatree.cpp:27:15: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   27 |     scanf("%lld %lld", &n, &d);
      |            ~~~^        ~~
      |               |        |
      |               |        int*
      |               long long int*
      |            %d
catinatree.cpp:27:20: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
   27 |     scanf("%lld %lld", &n, &d);
      |                 ~~~^       ~~
      |                    |       |
      |                    |       int*
      |                    long long int*
      |                 %d
catinatree.cpp:33:19: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   33 |         scanf("%lld", &a);
      |                ~~~^   ~~
      |                   |   |
      |                   |   int*
      |                   long long int*
      |                %d
catinatree.cpp:36:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
   36 |     printf("%lld\n", dfs(0).first);
      |             ~~~^     ~~~~~~~~~~~~
      |                |            |
      |                |            int
      |                long long int
      |             %d
catinatree.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%lld %lld", &n, &d);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
catinatree.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%lld", &a);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...