Submission #101492

# Submission time Handle Problem Language Result Execution time Memory
101492 2019-03-19T03:17:03 Z rocketninja7 Chase (CEOI17_chase) C++14
0 / 100
4000 ms 12632 KB
#include <cstdio>
#include <vector>
using namespace std;

vector<int> adjList[100001];

long long int p[100001];
bool vis[100001];

int dp(int bread, int node){
    if(bread==0||vis[node]){
        return 0;
    }
    vis[node]=true;
    int ans=0;
    int temp=0;
    for(int i=0;i<adjList[node].size();i++){
        if(!vis[adjList[node][i]]){
            temp+=p[adjList[node][i]];
        }
    }
    for(int i=0;i<adjList[node].size();i++){
        ans=max(ans, max(dp(bread, adjList[node][i]), dp(bread-1, adjList[node][i])+temp));
    }
    return ans;
}

int main(){
    int n, v;
    scanf("%d%d", &n, &v);
    for(int i=1;i<n+1;i++){
        scanf("%d", &p[i]);
    }
    for(int i=0;i<n-1;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        adjList[a].push_back(b);
        adjList[b].push_back(a);
    }
    int ans=0;
    for(int i=1;i<n+1;i++){
        for(int j=1;j<n+1;j++){
            vis[j]=false;
        }
        ans=max(ans, dp(v, i));
    }
    printf("%d", ans);
    return 0;
}

Compilation message

chase.cpp: In function 'int dp(int, int)':
chase.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<adjList[node].size();i++){
                 ~^~~~~~~~~~~~~~~~~~~~~
chase.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<adjList[node].size();i++){
                 ~^~~~~~~~~~~~~~~~~~~~~
chase.cpp: In function 'int main()':
chase.cpp:32:26: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%d", &p[i]);
                     ~~~~~^
chase.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &v);
     ~~~~~^~~~~~~~~~~~~~~~
chase.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &p[i]);
         ~~~~~^~~~~~~~~~~~~
chase.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Incorrect 4 ms 2688 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Incorrect 4 ms 2688 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4006 ms 12632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Incorrect 4 ms 2688 KB Output isn't correct
4 Halted 0 ms 0 KB -