제출 #355374

#제출 시각아이디문제언어결과실행 시간메모리
355374spatarelCat in a tree (BOI17_catinatree)C++17
51 / 100
11 ms9324 KiB
#include <stdio.h> #include <algorithm> #include <vector> const int MAX_N = 1500; // 200000 int N, D; std::vector<int> children[MAX_N]; int maxN[MAX_N][1 + MAX_N]; void dfs(int u) { for (int v : children[u]) { dfs(v); } maxN[u][0] = 1; for (int v : children[u]) { maxN[u][0] += maxN[v][D - 1]; } std::vector<int> maxAdd(1 + D); for (int v : children[u]) { for (int d = 0; d < D; d++) { maxN[u][d + 1] += maxN[v][d]; } for (int d = 0; d < D - d - 2; d++) { maxAdd[d + 1] = std::max(maxAdd[d + 1], maxN[v][d] - maxN[v][D - d - 2]); } } for (int d = 0; d < D - d - 2; d++) { maxN[u][d + 1] = maxAdd[d + 1] + maxN[u][D - d - 1]; } for (int d = D - 1; d >= 1; d--) { maxN[u][d - 1] = std::max(maxN[u][d - 1], maxN[u][d]); } /* printf("maxN[%d] = {", u); for (int d = 0; d < D; d++) { printf("%d, ", maxN[u][d]); } printf("}\n");//*/ } int main() { scanf("%d%d", &N, &D); for (int i = 1; i < N; i++) { int xi; scanf("%d", &xi); children[xi].push_back(i); } dfs(0); int answer = maxN[0][0]; printf("%d\n", answer); return 0; }

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

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