제출 #1215812

#제출 시각아이디문제언어결과실행 시간메모리
1215812badge881Cat in a tree (BOI17_catinatree)C++20
100 / 100
50 ms12868 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("%d %d", &n, &d); adj.assign(n + 1, vector<int>()); for (int i = 1; i < n; ++i) { int a; scanf("%d", &a); adj[a].push_back(i); } printf("%lld\n", dfs(0).first); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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