답안 #44694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44694 2018-04-04T21:37:39 Z bogdan10bos Chase (CEOI17_chase) C++14
0 / 100
304 ms 137524 KB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;

LL ans;
int N, K;
int v[100005];
LL vec[100005];
LL dpup[100005][105][3];
vector<int> edg[100005];

void DFS(int nod, int fth)
{
    for(auto nxt: edg[nod])
    {
        if(nxt == fth)  continue;
        DFS(nxt, nod);

        for(int i = 0; i <= K; i++)
        {
            dpup[nod][i][0] = max({ dpup[nod][i][0], dpup[nxt][i][0], dpup[nxt][i][1] });
            dpup[nod][i][1] = max({ dpup[nod][i][1], dpup[nxt][i][2] });
            if(i > 0)   dpup[nod][i][2] = max({ dpup[nod][i][2], dpup[nxt][i - 1][0] + vec[nod], dpup[nxt][i - 1][1] + vec[nod] - v[nxt], dpup[nxt][i - 1][2] + vec[nod] - v[nxt] });

            ans = max({ ans, dpup[nod][i][0], dpup[nod][i][1], dpup[nod][i][2] });
        }
    }
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &K);
    for(int i = 1; i <= N; i++) scanf("%d", &v[i]);
    for(int i = 1; i < N; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        edg[x].push_back(y);
        edg[y].push_back(x);
        vec[x] += v[y];
        vec[y] += v[x];
    }

    ans = 0;
    DFS(1, 0);

    printf("%lld\n", ans);

    return 0;
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:41: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:42:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= N; i++) scanf("%d", &v[i]);
                                 ~~~~~^~~~~~~~~~~~~
chase.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2680 KB Output is correct
2 Incorrect 3 ms 2800 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2680 KB Output is correct
2 Incorrect 3 ms 2800 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 304 ms 137524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2680 KB Output is correct
2 Incorrect 3 ms 2800 KB Output isn't correct
3 Halted 0 ms 0 KB -