제출 #985574

#제출 시각아이디문제언어결과실행 시간메모리
985574AlebnChase (CEOI17_chase)C++14
30 / 100
216 ms94800 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n, k, x, y; vector<int> a, b; vector<vector<int>> graph, dp; void dfs(int i, int p) { for(auto j : graph[i]) { if(j != p) dfs(j, i); } for(int j = 0; j <= k; j++) { for(auto z : graph[i]) { if(z != p) { dp[i][j] = max(dp[i][j], max(dp[z][j], (j == k || dp[z][j + 1] == LLONG_MIN ? LLONG_MIN : dp[z][j + 1] + b[i] - (p == -1 ? 0 : a[p])))); } } } } signed main() { cin >> n >> k; a = vector<int>(n), b = vector<int>(n), graph = vector<vector<int>>(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n - 1; i++) { cin >> x >> y; x--, y--; graph[x].push_back(y); graph[y].push_back(x); } for(int i = 0; i < n; i++) { for(int j = 0; j < graph[i].size(); j++) b[i] += a[graph[i][j]]; } // dp = vector<vector<int>>(n, vector<int>(k + 1, LLONG_MIN)); for(int i = 0; i < n; i++) dp[i][k] = 0; dfs(0, -1); // x = 0; for(int j = 0; j <= k; j++) x = max(x, dp[0][j]); cout << x << "\n"; }

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

chase.cpp: In function 'int main()':
chase.cpp:34:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int j = 0; j < graph[i].size(); j++) b[i] += a[graph[i][j]];
      |                        ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...