Submission #759368

# Submission time Handle Problem Language Result Execution time Memory
759368 2023-06-16T08:37:19 Z bgnbvnbv Magic Tree (CEOI19_magictree) C++14
100 / 100
95 ms 42956 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
#define int ll
vector<ll>g[maxN];
map<int,int>mp[maxN];
ll t[maxN],c[maxN];
void dfs(ll u=1)
{
    for(int v:g[u])
    {
        dfs(v);
        if(mp[v].size()>mp[u].size()) mp[u].swap(mp[v]);
        for(auto zz:mp[v]) mp[u][zz.fi]+=zz.se;
        mp[v].clear();
    }
    if(t[u]>0)
    {
        ll tru=c[u];
        while(tru>0)
        {
            auto it=mp[u].upper_bound(t[u]);
            if(it==mp[u].end()) break;
            if(it->se<=tru)
            {
                tru-=it->se;
                mp[u].erase(it);
            }
            else
            {
                it->se-=tru;
                break;
            }
        }
        mp[u][t[u]]+=c[u];
    }
}
ll n,m,k,p[maxN];
void solve()
{
    cin >> n >> m >> k;
    for(int i=2;i<=n;i++) cin >> p[i],g[p[i]].pb(i);
    while(m--)
    {
        ll u;
        cin >> u;
        cin >> t[u] >> c[u];
    }
    ll ans=0;
    dfs();
    for(auto zz:mp[1]) ans+=zz.se;
    cout << ans;
}
 main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

magictree.cpp:63:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 |  main()
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14320 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14352 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 20440 KB Output is correct
2 Correct 34 ms 26732 KB Output is correct
3 Correct 95 ms 22692 KB Output is correct
4 Correct 54 ms 21264 KB Output is correct
5 Correct 71 ms 23276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14552 KB Output is correct
2 Correct 7 ms 14556 KB Output is correct
3 Correct 7 ms 14648 KB Output is correct
4 Correct 45 ms 38936 KB Output is correct
5 Correct 61 ms 42956 KB Output is correct
6 Correct 56 ms 39036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 18644 KB Output is correct
2 Correct 51 ms 20744 KB Output is correct
3 Correct 43 ms 28260 KB Output is correct
4 Correct 32 ms 19408 KB Output is correct
5 Correct 42 ms 39240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14320 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14352 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14356 KB Output is correct
10 Correct 48 ms 20020 KB Output is correct
11 Correct 49 ms 19944 KB Output is correct
12 Correct 43 ms 27640 KB Output is correct
13 Correct 37 ms 18760 KB Output is correct
14 Correct 41 ms 38476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15316 KB Output is correct
2 Correct 25 ms 18560 KB Output is correct
3 Correct 27 ms 18660 KB Output is correct
4 Correct 28 ms 18664 KB Output is correct
5 Correct 14 ms 17704 KB Output is correct
6 Correct 25 ms 21844 KB Output is correct
7 Correct 26 ms 26212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14320 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14352 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14356 KB Output is correct
10 Correct 7 ms 14552 KB Output is correct
11 Correct 7 ms 14556 KB Output is correct
12 Correct 7 ms 14648 KB Output is correct
13 Correct 45 ms 38936 KB Output is correct
14 Correct 61 ms 42956 KB Output is correct
15 Correct 56 ms 39036 KB Output is correct
16 Correct 48 ms 20020 KB Output is correct
17 Correct 49 ms 19944 KB Output is correct
18 Correct 43 ms 27640 KB Output is correct
19 Correct 37 ms 18760 KB Output is correct
20 Correct 41 ms 38476 KB Output is correct
21 Correct 17 ms 15772 KB Output is correct
22 Correct 49 ms 20156 KB Output is correct
23 Correct 60 ms 22092 KB Output is correct
24 Correct 81 ms 23744 KB Output is correct
25 Correct 49 ms 22688 KB Output is correct
26 Correct 67 ms 27640 KB Output is correct
27 Correct 61 ms 29516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14320 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14352 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14356 KB Output is correct
10 Correct 52 ms 20440 KB Output is correct
11 Correct 34 ms 26732 KB Output is correct
12 Correct 95 ms 22692 KB Output is correct
13 Correct 54 ms 21264 KB Output is correct
14 Correct 71 ms 23276 KB Output is correct
15 Correct 7 ms 14552 KB Output is correct
16 Correct 7 ms 14556 KB Output is correct
17 Correct 7 ms 14648 KB Output is correct
18 Correct 45 ms 38936 KB Output is correct
19 Correct 61 ms 42956 KB Output is correct
20 Correct 56 ms 39036 KB Output is correct
21 Correct 57 ms 18644 KB Output is correct
22 Correct 51 ms 20744 KB Output is correct
23 Correct 43 ms 28260 KB Output is correct
24 Correct 32 ms 19408 KB Output is correct
25 Correct 42 ms 39240 KB Output is correct
26 Correct 48 ms 20020 KB Output is correct
27 Correct 49 ms 19944 KB Output is correct
28 Correct 43 ms 27640 KB Output is correct
29 Correct 37 ms 18760 KB Output is correct
30 Correct 41 ms 38476 KB Output is correct
31 Correct 9 ms 15316 KB Output is correct
32 Correct 25 ms 18560 KB Output is correct
33 Correct 27 ms 18660 KB Output is correct
34 Correct 28 ms 18664 KB Output is correct
35 Correct 14 ms 17704 KB Output is correct
36 Correct 25 ms 21844 KB Output is correct
37 Correct 26 ms 26212 KB Output is correct
38 Correct 17 ms 15772 KB Output is correct
39 Correct 49 ms 20156 KB Output is correct
40 Correct 60 ms 22092 KB Output is correct
41 Correct 81 ms 23744 KB Output is correct
42 Correct 49 ms 22688 KB Output is correct
43 Correct 67 ms 27640 KB Output is correct
44 Correct 61 ms 29516 KB Output is correct
45 Correct 19 ms 15964 KB Output is correct
46 Correct 53 ms 20464 KB Output is correct
47 Correct 74 ms 22468 KB Output is correct
48 Correct 91 ms 24656 KB Output is correct
49 Correct 53 ms 23316 KB Output is correct
50 Correct 75 ms 28568 KB Output is correct
51 Correct 69 ms 30400 KB Output is correct