Submission #990466

# Submission time Handle Problem Language Result Execution time Memory
990466 2024-05-30T13:26:15 Z asdasdqwer Magic Tree (CEOI19_magictree) C++14
100 / 100
138 ms 37972 KB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t

signed main() {
    int n,m,k;cin>>n>>m>>k;
    vector<int> p(n, -1);
    vector<vector<int>> child(n);

    for (int i=1;i<n;i++) {
        int c;cin>>c;c--;
        p[i]=c;
        child[c].push_back(i);
    }

    vector<int> day(n), juice(n);

    for (int i=0;i<m;i++) {
        int v,d,w;cin>>v>>d>>w;v--;d--;
        day[v]=d;
        juice[v]=w;
    }

    vector<map<int,int>> dp(n);
    function<void(int)> dfs=[&](int node) {
        if (child[node].size() == 0) {
            dp[node][day[node]] = juice[node];
            return;
        }

        int mx = 0;
        for (int x : child[node]) {
            dfs(x);
            mx = max(mx, (int)dp[x].size());
        }

        int id = -1;
        for (int x : child[node]) {
            if ((int)dp[x].size() == mx) {
                dp[x].swap(dp[node]);
                id = x;
                break;
            }
        }

        for (int x : child[node]) {
            if (x == id) continue;
            for (auto [time, inc] : dp[x]) {
                dp[node][time] += inc;
            }
        }

        vector<int> rem;
        int sm = 0;
        auto it = dp[node].upper_bound(day[node]);

        while (it != dp[node].end() && sm <= juice[node]) {
            sm += (*it).second;
            if (sm <= juice[node]) {
                rem.push_back((*it).first);
            }

            it = next(it);
        }

        for (int x:rem) {
            dp[node].erase(x);
        }

        dp[node][day[node]] += juice[node];
        
        it = dp[node].upper_bound(day[node]);
        if (it != dp[node].end()) {
            dp[node][(*it).first] = sm - juice[node];
        }
    };
    
    dfs(0);

    int sm = 0;
    for (auto [x, y] : dp[0]) {
        sm += y;
    }

    cout<<sm<<"\n";
}

Compilation message

magictree.cpp: In lambda function:
magictree.cpp:49:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |             for (auto [time, inc] : dp[x]) {
      |                       ^
magictree.cpp: In function 'int main()':
magictree.cpp:82:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |     for (auto [x, y] : dp[0]) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 22988 KB Output is correct
2 Correct 53 ms 23796 KB Output is correct
3 Correct 138 ms 37972 KB Output is correct
4 Correct 93 ms 22468 KB Output is correct
5 Correct 118 ms 24604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 82 ms 33560 KB Output is correct
5 Correct 107 ms 37400 KB Output is correct
6 Correct 103 ms 33580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 17748 KB Output is correct
2 Correct 80 ms 16720 KB Output is correct
3 Correct 80 ms 23124 KB Output is correct
4 Correct 63 ms 18628 KB Output is correct
5 Correct 80 ms 33872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 74 ms 20044 KB Output is correct
11 Correct 82 ms 19008 KB Output is correct
12 Correct 67 ms 22612 KB Output is correct
13 Correct 54 ms 17860 KB Output is correct
14 Correct 71 ms 33084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3416 KB Output is correct
2 Correct 35 ms 15440 KB Output is correct
3 Correct 44 ms 15444 KB Output is correct
4 Correct 35 ms 15444 KB Output is correct
5 Correct 20 ms 17100 KB Output is correct
6 Correct 34 ms 19540 KB Output is correct
7 Correct 35 ms 21592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 82 ms 33560 KB Output is correct
14 Correct 107 ms 37400 KB Output is correct
15 Correct 103 ms 33580 KB Output is correct
16 Correct 74 ms 20044 KB Output is correct
17 Correct 82 ms 19008 KB Output is correct
18 Correct 67 ms 22612 KB Output is correct
19 Correct 54 ms 17860 KB Output is correct
20 Correct 71 ms 33084 KB Output is correct
21 Correct 19 ms 5676 KB Output is correct
22 Correct 73 ms 22612 KB Output is correct
23 Correct 82 ms 26064 KB Output is correct
24 Correct 111 ms 32448 KB Output is correct
25 Correct 74 ms 21960 KB Output is correct
26 Correct 106 ms 24592 KB Output is correct
27 Correct 111 ms 24400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 72 ms 22988 KB Output is correct
11 Correct 53 ms 23796 KB Output is correct
12 Correct 138 ms 37972 KB Output is correct
13 Correct 93 ms 22468 KB Output is correct
14 Correct 118 ms 24604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 82 ms 33560 KB Output is correct
19 Correct 107 ms 37400 KB Output is correct
20 Correct 103 ms 33580 KB Output is correct
21 Correct 80 ms 17748 KB Output is correct
22 Correct 80 ms 16720 KB Output is correct
23 Correct 80 ms 23124 KB Output is correct
24 Correct 63 ms 18628 KB Output is correct
25 Correct 80 ms 33872 KB Output is correct
26 Correct 74 ms 20044 KB Output is correct
27 Correct 82 ms 19008 KB Output is correct
28 Correct 67 ms 22612 KB Output is correct
29 Correct 54 ms 17860 KB Output is correct
30 Correct 71 ms 33084 KB Output is correct
31 Correct 8 ms 3416 KB Output is correct
32 Correct 35 ms 15440 KB Output is correct
33 Correct 44 ms 15444 KB Output is correct
34 Correct 35 ms 15444 KB Output is correct
35 Correct 20 ms 17100 KB Output is correct
36 Correct 34 ms 19540 KB Output is correct
37 Correct 35 ms 21592 KB Output is correct
38 Correct 19 ms 5676 KB Output is correct
39 Correct 73 ms 22612 KB Output is correct
40 Correct 82 ms 26064 KB Output is correct
41 Correct 111 ms 32448 KB Output is correct
42 Correct 74 ms 21960 KB Output is correct
43 Correct 106 ms 24592 KB Output is correct
44 Correct 111 ms 24400 KB Output is correct
45 Correct 23 ms 5976 KB Output is correct
46 Correct 82 ms 23636 KB Output is correct
47 Correct 94 ms 27116 KB Output is correct
48 Correct 130 ms 35664 KB Output is correct
49 Correct 97 ms 22468 KB Output is correct
50 Correct 124 ms 25684 KB Output is correct
51 Correct 120 ms 25348 KB Output is correct