답안 #850500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850500 2023-09-16T17:52:18 Z Benmath Chase (CEOI17_chase) C++14
30 / 100
191 ms 149584 KB
/******************************************************************************

                              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[100010];
vector<int> adjl[100010];
int vis[100010];
long long int dpnula[100010][105];
long long int dp[100010][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);
  
    cout << dp[1][v];
}

Compilation message

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++){
      |                    ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 94036 KB Output is correct
2 Correct 147 ms 96336 KB Output is correct
3 Correct 94 ms 9924 KB Output is correct
4 Correct 150 ms 145488 KB Output is correct
5 Correct 187 ms 149584 KB Output is correct
6 Correct 191 ms 149584 KB Output is correct
7 Correct 185 ms 149328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3160 KB Output isn't correct
2 Halted 0 ms 0 KB -