답안 #578522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578522 2022-06-17T08:01:03 Z andrei_boaca Chase (CEOI17_chase) C++14
70 / 100
778 ms 96096 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll n,v,p[100005],par[100005],dp[100005][105];
vector<ll> muchii[100005];
ll ans=0;
ll MAXROOT=1;
void dfs(int nod)
{
    for(int i=1;i<=v;i++)
        dp[nod][i]=0;
    ll suma=0;
    int cnt=0;
    for(int i:muchii[nod])
        if(i!=par[nod])
        {
            suma+=p[i];
            par[i]=nod;
            cnt++;
            dfs(i);
        }
    for(int j=1;j<=v;j++)
    {
        dp[nod][j]=dp[nod][j-1];
        for(int i:muchii[nod])
            if(i!=par[nod])
            {
                dp[nod][j]=max(dp[nod][j],dp[i][j]);
                dp[nod][j]=max(dp[nod][j],dp[i][j-1]+suma);
            }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>v;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        muchii[a].push_back(b);
        muchii[b].push_back(a);
    }
    if(n<=1000)
        MAXROOT=n;
    for(int root=1;root<=MAXROOT;root++)
    {
        for(int i=1;i<=n;i++)
            par[i]=0;
        dfs(root);
        for(int i=1;i<=v;i++)
            ans=max(ans,dp[root][i]);
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2680 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2680 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 778 ms 3604 KB Output is correct
8 Correct 47 ms 3540 KB Output is correct
9 Correct 42 ms 3540 KB Output is correct
10 Correct 735 ms 3660 KB Output is correct
11 Correct 259 ms 3572 KB Output is correct
12 Correct 71 ms 3560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 96096 KB Output is correct
2 Correct 192 ms 96060 KB Output is correct
3 Correct 214 ms 92344 KB Output is correct
4 Correct 94 ms 92124 KB Output is correct
5 Correct 171 ms 92240 KB Output is correct
6 Correct 183 ms 92196 KB Output is correct
7 Correct 174 ms 92224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2680 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 778 ms 3604 KB Output is correct
8 Correct 47 ms 3540 KB Output is correct
9 Correct 42 ms 3540 KB Output is correct
10 Correct 735 ms 3660 KB Output is correct
11 Correct 259 ms 3572 KB Output is correct
12 Correct 71 ms 3560 KB Output is correct
13 Correct 175 ms 96096 KB Output is correct
14 Correct 192 ms 96060 KB Output is correct
15 Correct 214 ms 92344 KB Output is correct
16 Correct 94 ms 92124 KB Output is correct
17 Correct 171 ms 92240 KB Output is correct
18 Correct 183 ms 92196 KB Output is correct
19 Correct 174 ms 92224 KB Output is correct
20 Incorrect 179 ms 92208 KB Output isn't correct
21 Halted 0 ms 0 KB -