Submission #469038

# Submission time Handle Problem Language Result Execution time Memory
469038 2021-08-30T13:21:28 Z wdjpng Chase (CEOI17_chase) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
    
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
    
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
    
using namespace std;
    
int n,v;
vector<int>p;
vector<vector<int>>mem;
vector<vector<signed>>E;
vector<vector<signed>>usednode;
vector<vector<int>>maxwithnode;
vector<vector<int>>maxnonode;

int dfs(int pos, int bc, int parent)
{
    if(mem[pos][bc]!=-1) return mem[pos][bc];
    if(bc==0) return 0;
    
    int sum = 0;
    for(int w : E[pos])
    {
        if(w==parent) continue;
        sum+=p[w];
    }
    
    int maxx = 0;
    maxwithnode[pos][bc]=0;
    usednode[pos][bc] = -1;

    for(int w : E[pos])
    {
        if(w==parent) continue;
        int cur = max(dfs(w, bc, pos), dfs(w, bc-1, pos) + sum));
        if(cur>maxwithnode[pos][bc])
        {
            maxwithnode[pos][bc] = cur;
            usednode[pos][bc] = cur;
        }
        maxx=max(maxx, cur);
    }

    maxnonode[pos][bc]=0;
    if(usednode[pos][bc]!=-1)
    {
        for(int w : E[pos])
        {
            if(w==parent||w==usednode[pos][bc]) continue;
            int cur = max(dfs(w, bc, pos), dfs(w, bc-1, pos) + sum - p[usednode[pos][cur]]);
            maxnonode[pos][bc] = max(maxnonode[pos][bc], cur);
        }
    }

    return mem[pos][bc] = maxx;
}
    
int bruteforce()
{
    int maxx=0;
    rep(i, n) 
    {
        mem.assign(n+1, vector<int>(v+1, -1));
        maxx=max(maxx, dfs(i+1, v, -1));
    }
    return maxx;
}

int mx=0;
void meta_dfs(int pos, int parent)
{
    mx = max(mx, dfs(pos, v, -1));

    for(int w : E[v])
    {
        if(w==parent) continue;
        for(int i = 1; i<= v; i++)
        {
            mem[pos][i] = maxwithnode[pos][i];
            if(usednode[pos][i]==w) mem[pos][i] = maxnonode[pos][i];
        }

        mem[w][v] = -1;
        meta_dfs(w,pos);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>v;
    p.resize(n+1);
    rep(i, n) cin>>p[i+1];
    
    E.resize(n+1);
    mem.assign(n+1, vector<int>(v+1, -1));
    
    rep(i,n-1)
    {
        signed a,b;
        cin>>a>>b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    //int maxx = dfs(1, v, -1);
    //if(n<=1000) maxx = bruteforce();
    //cout<<maxx<<"\n";
    usednode.assign(n+1, vector<signed>(v+1));
    maxwithnode.assign(n+1, vector<int>(v+1));
    maxnonode.assign(n+1, vector<int>(v+1));

    meta_dfs(1, -1);
    cout<<mx<<"\n";
}

Compilation message

chase.cpp: In function 'long long int dfs(long long int, long long int, long long int)':
chase.cpp:38:64: error: expected ',' or ';' before ')' token
   38 |         int cur = max(dfs(w, bc, pos), dfs(w, bc-1, pos) + sum));
      |                                                                ^