답안 #764655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764655 2023-06-23T18:08:29 Z groshi Magic Tree (CEOI19_magictree) C++17
3 / 100
93 ms 38324 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;
    auto it=w[x].mapka.upper_bound(w[x].kiedy);
    int maxx=0;
    if(it==w[x].mapka.end())
    {
        w[x].mapka[w[x].kiedy]+=w[x].ile;
        return;
    }
    int suma=0;
    int pomoc=w[x].ile;
    vector<int> usun;
    while(it!=w[x].mapka.end() && w[x].ile>suma)
    {
        maxx=max(maxx,it->first);
        suma+=it->second;
        usun.push_back(it->first);
        it++;
    }
    for(int i=0;i<usun.size();i++)
        w[x].mapka.erase(usun[i]);
    if(w[x].ile>suma)
        w[x].mapka[w[x].kiedy]+=w[x].ile;
    else{
        w[x].mapka[maxx]+=suma;
    }
}
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++)
      |                 ~^~~~~~~~~~~~~~
magictree.cpp:40: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]
   40 |     for(int i=0;i<usun.size();i++)
      |                 ~^~~~~~~~~~~~
magictree.cpp:31:9: warning: unused variable 'pomoc' [-Wunused-variable]
   31 |     int pomoc=w[x].ile;
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 19436 KB Output is correct
2 Correct 42 ms 21120 KB Output is correct
3 Correct 92 ms 38324 KB Output is correct
4 Correct 60 ms 21096 KB Output is correct
5 Correct 93 ms 23348 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 43 ms 16428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 21 ms 11556 KB Output is correct
3 Correct 25 ms 11492 KB Output is correct
4 Correct 22 ms 11596 KB Output is correct
5 Correct 9 ms 10312 KB Output is correct
6 Incorrect 20 ms 14060 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -