답안 #132152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132152 2019-07-18T11:00:19 Z Vardanyan Chase (CEOI17_chase) C++14
0 / 100
959 ms 8632 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 100*1000+5;
int d[N];
long long ans = 0;
int qn;
vector<int> g[N];
void dfs(int v,int p = -1,int hm = qn,long long now = 0){
    if(hm == 0){
        ans = max(ans,now);
        return;
    }
    for(int i = 0;i<g[v].size();i++){
        int to = g[v][i];
        if(to == p) continue;
        now+=d[to];
    }
    for(int i = 0;i<g[v].size();i++){
        int to = g[v][i];
        if(to == p) continue;
        dfs(to,v,hm-1,now);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n>>qn;
    for(int i = 1;i<=n;i++) cin>>d[i];
    for(int i = 0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i = 1;i<=n;i++){
        dfs(i);
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

chase.cpp: In function 'void dfs(int, int, int, long long int)':
chase.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
chase.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 959 ms 8632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -