Submission #469010

# Submission time Handle Problem Language Result Execution time Memory
469010 2021-08-30T11:52:38 Z wdjpng Chase (CEOI17_chase) C++17
70 / 100
2359 ms 94740 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<int>>E;
     
    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;
        for(int w : E[pos])
        {
            if(w==parent) continue;
            if(parent!=-1) maxx=max(maxx, dfs(w, bc, pos));
            maxx=max(maxx, dfs(w, bc-1, pos) + sum);
        }
     
        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;
    }
     
    signed main()
    {
        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)
        {
            int 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";
    }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2359 ms 1212 KB Output is correct
8 Correct 107 ms 460 KB Output is correct
9 Correct 33 ms 332 KB Output is correct
10 Correct 323 ms 1100 KB Output is correct
11 Correct 280 ms 588 KB Output is correct
12 Correct 221 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 610 ms 94740 KB Output is correct
2 Correct 581 ms 94660 KB Output is correct
3 Correct 163 ms 89504 KB Output is correct
4 Correct 135 ms 12704 KB Output is correct
5 Correct 731 ms 89260 KB Output is correct
6 Correct 650 ms 89360 KB Output is correct
7 Correct 733 ms 89492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2359 ms 1212 KB Output is correct
8 Correct 107 ms 460 KB Output is correct
9 Correct 33 ms 332 KB Output is correct
10 Correct 323 ms 1100 KB Output is correct
11 Correct 280 ms 588 KB Output is correct
12 Correct 221 ms 472 KB Output is correct
13 Correct 610 ms 94740 KB Output is correct
14 Correct 581 ms 94660 KB Output is correct
15 Correct 163 ms 89504 KB Output is correct
16 Correct 135 ms 12704 KB Output is correct
17 Correct 731 ms 89260 KB Output is correct
18 Correct 650 ms 89360 KB Output is correct
19 Correct 733 ms 89492 KB Output is correct
20 Incorrect 264 ms 89440 KB Output isn't correct
21 Halted 0 ms 0 KB -