Submission #276669

# Submission time Handle Problem Language Result Execution time Memory
276669 2020-08-20T14:54:49 Z Mercenary Magic Tree (CEOI19_magictree) C++14
100 / 100
157 ms 38648 KB
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair

using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int maxn = 1e5 + 5;
int d[maxn] , w[maxn];
int n , m , k;
vector<int> adj[maxn];

map<int,ll> * dfs(int u){
    auto cur = new map<int,ll>;
    for(auto & c : adj[u]){
        auto tmp = dfs(c);
        if(tmp->size() > cur->size())swap(tmp,cur);
        for(auto val : (*tmp))(*cur)[val.first] += val.second;
    }
    if(d[u]){
        int val = w[u];
        while(true){
            auto it = cur->upper_bound(d[u]);
            if(it == cur->end())break;
            if(it->second <= val){
                val -= it->second;
                cur->erase(it);
            }else{
                (*cur)[it->first] -= val;
                break;
            }
        }
        (*cur)[d[u]] += w[u];
    }
    return cur;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    cin >> n >> m >> k;
    for(int i = 2 ; i <= n ; ++i){
        int p;cin >> p;adj[p].pb(i);
    }
    for(int i = 1 ; i <= m ; ++i){
        int u;cin >> u;cin >> d[u] >> w[u];
    }
    ll ans = 0;
    auto res = dfs(1);
    for(auto c : (*res))ans += c.second;
    cout << ans << endl;
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   43 |         freopen(taskname".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   44 |         freopen(taskname".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 3 ms 2744 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 20072 KB Output is correct
2 Correct 56 ms 20608 KB Output is correct
3 Correct 136 ms 38648 KB Output is correct
4 Correct 100 ms 21620 KB Output is correct
5 Correct 123 ms 23444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 2 ms 2944 KB Output is correct
3 Correct 3 ms 2944 KB Output is correct
4 Correct 64 ms 27256 KB Output is correct
5 Correct 84 ms 31228 KB Output is correct
6 Correct 85 ms 27384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 17144 KB Output is correct
2 Correct 72 ms 16544 KB Output is correct
3 Correct 67 ms 20472 KB Output is correct
4 Correct 48 ms 17524 KB Output is correct
5 Correct 60 ms 27512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 3 ms 2744 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 80 ms 19380 KB Output is correct
11 Correct 77 ms 18336 KB Output is correct
12 Correct 64 ms 19832 KB Output is correct
13 Correct 46 ms 16900 KB Output is correct
14 Correct 57 ms 26872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4736 KB Output is correct
2 Correct 37 ms 12152 KB Output is correct
3 Correct 45 ms 12152 KB Output is correct
4 Correct 35 ms 12152 KB Output is correct
5 Correct 17 ms 10492 KB Output is correct
6 Correct 35 ms 14328 KB Output is correct
7 Correct 42 ms 17944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 3 ms 2744 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 3 ms 2944 KB Output is correct
11 Correct 2 ms 2944 KB Output is correct
12 Correct 3 ms 2944 KB Output is correct
13 Correct 64 ms 27256 KB Output is correct
14 Correct 84 ms 31228 KB Output is correct
15 Correct 85 ms 27384 KB Output is correct
16 Correct 80 ms 19380 KB Output is correct
17 Correct 77 ms 18336 KB Output is correct
18 Correct 64 ms 19832 KB Output is correct
19 Correct 46 ms 16900 KB Output is correct
20 Correct 57 ms 26872 KB Output is correct
21 Correct 20 ms 7288 KB Output is correct
22 Correct 91 ms 20344 KB Output is correct
23 Correct 93 ms 23544 KB Output is correct
24 Correct 129 ms 31992 KB Output is correct
25 Correct 100 ms 20852 KB Output is correct
26 Correct 144 ms 22776 KB Output is correct
27 Correct 126 ms 21752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 3 ms 2744 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 70 ms 20072 KB Output is correct
11 Correct 56 ms 20608 KB Output is correct
12 Correct 136 ms 38648 KB Output is correct
13 Correct 100 ms 21620 KB Output is correct
14 Correct 123 ms 23444 KB Output is correct
15 Correct 3 ms 2944 KB Output is correct
16 Correct 2 ms 2944 KB Output is correct
17 Correct 3 ms 2944 KB Output is correct
18 Correct 64 ms 27256 KB Output is correct
19 Correct 84 ms 31228 KB Output is correct
20 Correct 85 ms 27384 KB Output is correct
21 Correct 75 ms 17144 KB Output is correct
22 Correct 72 ms 16544 KB Output is correct
23 Correct 67 ms 20472 KB Output is correct
24 Correct 48 ms 17524 KB Output is correct
25 Correct 60 ms 27512 KB Output is correct
26 Correct 80 ms 19380 KB Output is correct
27 Correct 77 ms 18336 KB Output is correct
28 Correct 64 ms 19832 KB Output is correct
29 Correct 46 ms 16900 KB Output is correct
30 Correct 57 ms 26872 KB Output is correct
31 Correct 8 ms 4736 KB Output is correct
32 Correct 37 ms 12152 KB Output is correct
33 Correct 45 ms 12152 KB Output is correct
34 Correct 35 ms 12152 KB Output is correct
35 Correct 17 ms 10492 KB Output is correct
36 Correct 35 ms 14328 KB Output is correct
37 Correct 42 ms 17944 KB Output is correct
38 Correct 20 ms 7288 KB Output is correct
39 Correct 91 ms 20344 KB Output is correct
40 Correct 93 ms 23544 KB Output is correct
41 Correct 129 ms 31992 KB Output is correct
42 Correct 100 ms 20852 KB Output is correct
43 Correct 144 ms 22776 KB Output is correct
44 Correct 126 ms 21752 KB Output is correct
45 Correct 28 ms 7808 KB Output is correct
46 Correct 92 ms 21496 KB Output is correct
47 Correct 113 ms 24884 KB Output is correct
48 Correct 157 ms 34936 KB Output is correct
49 Correct 104 ms 21748 KB Output is correct
50 Correct 126 ms 23800 KB Output is correct
51 Correct 111 ms 22648 KB Output is correct