이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int n;
int v;
long long int p[1010];
vector<int> adjl[1010];
int vis[1010];
long long int dpnula[1010][105];
long long int dp[1010][105];
void dfs(int s){
vis[s]++;
long long int suma = 0;
for (int i = 0;i< adjl[s].size(); i++){
if(vis[adjl[s][i]] == 0){
suma = suma + p[adjl[s][i]];
}
}
for (int i = 0;i < adjl[s].size(); i++){
if (vis[adjl[s][i]] == 0){
dfs(adjl[s][i]);
for (int j = 1; j <=v; j++){
dpnula[s][j] = max(dpnula[s][j], dpnula[adjl[s][i]][j-1] + suma);
dpnula[s][j] = max(dpnula[s][j], dp[adjl[s][i]][j]);
dp[s][j] = max(dp[s][j], dpnula[adjl[s][i]][j-1] + suma);
dp[s][j] = max(dp[s][j], dp[adjl[s][i]][j]);
}
}
}
}
int main(){
cin >> n;
cin >> v;
for(int i = 1; i <= n; i++){
cin >> p[i];
}
for(int i = 0; i < (n-1); i++){
int a, b;
cin >> a >> b;
adjl[a].push_back(b);
adjl[b].push_back(a);
}
dfs(1);
long long int ans = 0;
for(int i = 1; i<=n; i++){
for (int k = 1; k<=n; k++){
for(int t = 0; t<=v; t++){
dpnula[k][t] = 0;
dp[k][t] = 0;
}
vis[k] = 0;
}
dfs(i);
ans = max(ans, dp[i][v]);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
chase.cpp: In function 'void dfs(int)':
chase.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0;i< adjl[s].size(); i++){
| ~^~~~~~~~~~~~~~~~
chase.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 0;i < adjl[s].size(); i++){
| ~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |