답안 #764657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764657 2023-06-23T18:25:36 Z groshi Magic Tree (CEOI19_magictree) C++17
3 / 100
99 ms 35748 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(pomoc);
        }
        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++)
      |                 ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 18336 KB Output is correct
2 Correct 35 ms 18316 KB Output is correct
3 Correct 99 ms 35748 KB Output is correct
4 Correct 55 ms 19016 KB Output is correct
5 Correct 68 ms 20448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 14636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -