Submission #242391

# Submission time Handle Problem Language Result Execution time Memory
242391 2020-06-27T14:31:30 Z tqbfjotld Magic Tree (CEOI19_magictree) C++14
100 / 100
191 ms 29048 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool fruit[100005];
int day[100005];
int val[100005];
vector<int> adjl[100005];
int n,m,k;

map<int,int> func(int node){
    map<int,int> ans;
    if (adjl[node].size()>=1){
        ans = func(adjl[node][0]);
    }
    for (int x = 1; x<adjl[node].size(); x++){
        int ch = adjl[node][x];
        auto res = func(ch);
        if (res.size()>ans.size()){
            swap(res,ans);
        }
        for (auto item : res){
            ans[item.first] += item.second;
        }
    }
    if (fruit[node]){
        ans[day[node]] += val[node];
        int t = val[node];
        auto it = ans.upper_bound(day[node]);
        while (t>0&& it!=ans.end()){
            if ((*it).second<=t){
                t -= (*it).second;
                it = ans.erase(it);
            }
            else{
                ans[(*it).first] -= t;
                break;
            }
        }
    }
    return ans;
}

main(){
    scanf("%lld%lld%lld",&n,&m,&k);
    for (int x = 1; x<n; x++){
        int t;
        scanf("%lld",&t);
        t--;
        adjl[t].push_back(x);
    }
    for (int x = 0; x<m; x++){
        int a,b;
        long long c;
        scanf("%lld%lld%lld",&a,&b,&c);
        a--;
        fruit[a] = true;
        day[a] = b;
        val[a] = c;
    }
    auto res = func(0);
    long long ans = 0;
    for (auto x : res){
        ans += x.second;
    }
    printf("%lld",ans);
}

Compilation message

magictree.cpp: In function 'std::map<long long int, long long int> func(long long int)':
magictree.cpp:15:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x = 1; x<adjl[node].size(); x++){
                     ~^~~~~~~~~~~~~~~~~~
magictree.cpp: At global scope:
magictree.cpp:43:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
magictree.cpp: In function 'int main()':
magictree.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld%lld",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&t);
         ~~~~~^~~~~~~~~~~
magictree.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 8440 KB Output is correct
2 Correct 58 ms 15228 KB Output is correct
3 Correct 156 ms 12792 KB Output is correct
4 Correct 97 ms 10860 KB Output is correct
5 Correct 174 ms 13432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2944 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
3 Correct 6 ms 2944 KB Output is correct
4 Correct 72 ms 25080 KB Output is correct
5 Correct 107 ms 29048 KB Output is correct
6 Correct 89 ms 25080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 6648 KB Output is correct
2 Correct 89 ms 8408 KB Output is correct
3 Correct 77 ms 15868 KB Output is correct
4 Correct 65 ms 7024 KB Output is correct
5 Correct 72 ms 26812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
10 Correct 90 ms 6528 KB Output is correct
11 Correct 106 ms 6648 KB Output is correct
12 Correct 77 ms 14200 KB Output is correct
13 Correct 54 ms 5620 KB Output is correct
14 Correct 65 ms 25080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3584 KB Output is correct
2 Correct 36 ms 6648 KB Output is correct
3 Correct 42 ms 6648 KB Output is correct
4 Correct 37 ms 6648 KB Output is correct
5 Correct 20 ms 5496 KB Output is correct
6 Correct 40 ms 9856 KB Output is correct
7 Correct 39 ms 14200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
10 Correct 9 ms 2944 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 6 ms 2944 KB Output is correct
13 Correct 72 ms 25080 KB Output is correct
14 Correct 107 ms 29048 KB Output is correct
15 Correct 89 ms 25080 KB Output is correct
16 Correct 90 ms 6528 KB Output is correct
17 Correct 106 ms 6648 KB Output is correct
18 Correct 77 ms 14200 KB Output is correct
19 Correct 54 ms 5620 KB Output is correct
20 Correct 65 ms 25080 KB Output is correct
21 Correct 26 ms 3968 KB Output is correct
22 Correct 89 ms 7144 KB Output is correct
23 Correct 112 ms 8824 KB Output is correct
24 Correct 157 ms 9848 KB Output is correct
25 Correct 98 ms 9192 KB Output is correct
26 Correct 113 ms 13816 KB Output is correct
27 Correct 100 ms 15736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
10 Correct 78 ms 8440 KB Output is correct
11 Correct 58 ms 15228 KB Output is correct
12 Correct 156 ms 12792 KB Output is correct
13 Correct 97 ms 10860 KB Output is correct
14 Correct 174 ms 13432 KB Output is correct
15 Correct 9 ms 2944 KB Output is correct
16 Correct 6 ms 2944 KB Output is correct
17 Correct 6 ms 2944 KB Output is correct
18 Correct 72 ms 25080 KB Output is correct
19 Correct 107 ms 29048 KB Output is correct
20 Correct 89 ms 25080 KB Output is correct
21 Correct 86 ms 6648 KB Output is correct
22 Correct 89 ms 8408 KB Output is correct
23 Correct 77 ms 15868 KB Output is correct
24 Correct 65 ms 7024 KB Output is correct
25 Correct 72 ms 26812 KB Output is correct
26 Correct 90 ms 6528 KB Output is correct
27 Correct 106 ms 6648 KB Output is correct
28 Correct 77 ms 14200 KB Output is correct
29 Correct 54 ms 5620 KB Output is correct
30 Correct 65 ms 25080 KB Output is correct
31 Correct 12 ms 3584 KB Output is correct
32 Correct 36 ms 6648 KB Output is correct
33 Correct 42 ms 6648 KB Output is correct
34 Correct 37 ms 6648 KB Output is correct
35 Correct 20 ms 5496 KB Output is correct
36 Correct 40 ms 9856 KB Output is correct
37 Correct 39 ms 14200 KB Output is correct
38 Correct 26 ms 3968 KB Output is correct
39 Correct 89 ms 7144 KB Output is correct
40 Correct 112 ms 8824 KB Output is correct
41 Correct 157 ms 9848 KB Output is correct
42 Correct 98 ms 9192 KB Output is correct
43 Correct 113 ms 13816 KB Output is correct
44 Correct 100 ms 15736 KB Output is correct
45 Correct 27 ms 4096 KB Output is correct
46 Correct 92 ms 8056 KB Output is correct
47 Correct 101 ms 9980 KB Output is correct
48 Correct 191 ms 12408 KB Output is correct
49 Correct 92 ms 10984 KB Output is correct
50 Correct 129 ms 16120 KB Output is correct
51 Correct 115 ms 18040 KB Output is correct