Submission #764658

# Submission time Handle Problem Language Result Execution time Memory
764658 2023-06-23T18:26:37 Z groshi Magic Tree (CEOI19_magictree) C++17
100 / 100
97 ms 35896 KB
#include<bits/stdc++.h>
#define int long long

using namespace std;
struct wi{
    vector<int> Q;
    int kiedy=0,ile=0;
    map<int,int> mapka;
}*w;
void reku(int x)
{
    for(int i=0;i<w[x].Q.size();i++)
    {
        int pom=w[x].Q[i];
        reku(pom);
        if(w[pom].mapka.size()>w[x].mapka.size())
            swap(w[pom].mapka,w[x].mapka);
        for(auto it=w[pom].mapka.begin();it!=w[pom].mapka.end();it++)
            w[x].mapka[it->first]+=it->second;
    }
    if(w[x].kiedy==0)
        return;
    int pomoc=w[x].ile;
    while(pomoc>0)
    {
        auto it=w[x].mapka.upper_bound(w[x].kiedy);
        if(it==w[x].mapka.end())
            break;
        if(it->second<=pomoc)
        {
            pomoc-=it->second;
            w[x].mapka.erase(it->first);
        }
        else{
            it->second-=pomoc;
            break;
        }
    }
    w[x].mapka[w[x].kiedy]+=w[x].ile;
}
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,m,k,x,y,z;
    cin>>n>>m>>k;
    w=new wi[n+3];
    for(int i=2;i<=n;i++)
    {
        cin>>x;
        w[x].Q.push_back(i);
    }
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y>>z;
        w[x].kiedy=y;
        w[x].ile=z;
    }
    reku(1);
    int wynik=0;
    for(auto it=w[1].mapka.begin();it!=w[1].mapka.end();it++)
        wynik+=it->second;
    cout<<wynik;
    return 0;
}

Compilation message

magictree.cpp: In function 'void reku(long long int)':
magictree.cpp:12:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 18336 KB Output is correct
2 Correct 30 ms 18208 KB Output is correct
3 Correct 97 ms 35896 KB Output is correct
4 Correct 58 ms 19024 KB Output is correct
5 Correct 68 ms 20432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 37 ms 23368 KB Output is correct
5 Correct 58 ms 27304 KB Output is correct
6 Correct 53 ms 23468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 14392 KB Output is correct
2 Correct 68 ms 15776 KB Output is correct
3 Correct 39 ms 18452 KB Output is correct
4 Correct 40 ms 17016 KB Output is correct
5 Correct 34 ms 23500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 51 ms 18696 KB Output is correct
11 Correct 46 ms 17740 KB Output is correct
12 Correct 43 ms 17800 KB Output is correct
13 Correct 30 ms 16424 KB Output is correct
14 Correct 35 ms 22860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2516 KB Output is correct
2 Correct 20 ms 10964 KB Output is correct
3 Correct 24 ms 10952 KB Output is correct
4 Correct 21 ms 11016 KB Output is correct
5 Correct 9 ms 10068 KB Output is correct
6 Correct 19 ms 12544 KB Output is correct
7 Correct 21 ms 15752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 37 ms 23368 KB Output is correct
14 Correct 58 ms 27304 KB Output is correct
15 Correct 53 ms 23468 KB Output is correct
16 Correct 51 ms 18696 KB Output is correct
17 Correct 46 ms 17740 KB Output is correct
18 Correct 43 ms 17800 KB Output is correct
19 Correct 30 ms 16424 KB Output is correct
20 Correct 35 ms 22860 KB Output is correct
21 Correct 12 ms 5304 KB Output is correct
22 Correct 49 ms 19744 KB Output is correct
23 Correct 57 ms 23028 KB Output is correct
24 Correct 92 ms 31260 KB Output is correct
25 Correct 52 ms 20356 KB Output is correct
26 Correct 69 ms 21540 KB Output is correct
27 Correct 61 ms 19676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 43 ms 18336 KB Output is correct
11 Correct 30 ms 18208 KB Output is correct
12 Correct 97 ms 35896 KB Output is correct
13 Correct 58 ms 19024 KB Output is correct
14 Correct 68 ms 20432 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 37 ms 23368 KB Output is correct
19 Correct 58 ms 27304 KB Output is correct
20 Correct 53 ms 23468 KB Output is correct
21 Correct 51 ms 14392 KB Output is correct
22 Correct 68 ms 15776 KB Output is correct
23 Correct 39 ms 18452 KB Output is correct
24 Correct 40 ms 17016 KB Output is correct
25 Correct 34 ms 23500 KB Output is correct
26 Correct 51 ms 18696 KB Output is correct
27 Correct 46 ms 17740 KB Output is correct
28 Correct 43 ms 17800 KB Output is correct
29 Correct 30 ms 16424 KB Output is correct
30 Correct 35 ms 22860 KB Output is correct
31 Correct 4 ms 2516 KB Output is correct
32 Correct 20 ms 10964 KB Output is correct
33 Correct 24 ms 10952 KB Output is correct
34 Correct 21 ms 11016 KB Output is correct
35 Correct 9 ms 10068 KB Output is correct
36 Correct 19 ms 12544 KB Output is correct
37 Correct 21 ms 15752 KB Output is correct
38 Correct 12 ms 5304 KB Output is correct
39 Correct 49 ms 19744 KB Output is correct
40 Correct 57 ms 23028 KB Output is correct
41 Correct 92 ms 31260 KB Output is correct
42 Correct 52 ms 20356 KB Output is correct
43 Correct 69 ms 21540 KB Output is correct
44 Correct 61 ms 19676 KB Output is correct
45 Correct 13 ms 5716 KB Output is correct
46 Correct 50 ms 20824 KB Output is correct
47 Correct 64 ms 24236 KB Output is correct
48 Correct 93 ms 34336 KB Output is correct
49 Correct 57 ms 21064 KB Output is correct
50 Correct 78 ms 22496 KB Output is correct
51 Correct 70 ms 20612 KB Output is correct