Submission #163095

# Submission time Handle Problem Language Result Execution time Memory
163095 2019-11-11T11:07:03 Z arnold518 Chase (CEOI17_chase) C++14
30 / 100
288 ms 99248 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int MAXK = 100;

int N, K;
ll P[MAXN+10], S[MAXN+10], dp[MAXN+10][MAXK+10];
vector<int> adj[MAXN+10];

void dfs(int now, int bef)
{
    int i, j, chd=0;
    for(int nxt : adj[now])
    {
        if(nxt==bef) continue;
        dfs(nxt, now);
        S[now]+=P[nxt];
        chd++;
    }

    dp[now][0]=0;
    for(i=1; i<=K; i++)
    {
        ll val=0;
        for(int nxt : adj[now])
        {
            if(nxt==bef) continue;
            val=max(val, dp[nxt][i-1]);
            dp[now][i]=max(dp[now][i], dp[nxt][i]);
        }
        dp[now][i]=max(dp[now][i], S[now]+val);
    }

    //printf("%d : ", now);
    //for(i=0; i<=K; i++) printf("%lld ", dp[now][i]);
    //printf("\n");
}

int main()
{
    int i, j;

    scanf("%d%d", &N, &K);
    for(i=1; i<=N; i++) scanf("%lld", &P[i]);
    for(i=1; i<N; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1, 1);
    printf("%lld", dp[1][K]);
}

Compilation message

chase.cpp: In function 'void dfs(int, int)':
chase.cpp:17:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j, chd=0;
            ^
chase.cpp: In function 'int main()':
chase.cpp:46:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
chase.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &K);
     ~~~~~^~~~~~~~~~~~~~~~
chase.cpp:49:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%lld", &P[i]);
                         ~~~~~^~~~~~~~~~~~~~~
chase.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 252 ms 99068 KB Output is correct
2 Correct 254 ms 99248 KB Output is correct
3 Correct 288 ms 95272 KB Output is correct
4 Correct 163 ms 95656 KB Output is correct
5 Correct 243 ms 95708 KB Output is correct
6 Correct 269 ms 95864 KB Output is correct
7 Correct 245 ms 95812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -