39882023-03-07 16:40:26eokorTevefarmcpp11Wrong answer 6/5081ms5424 KiB
#include <bits/stdc++.h>

using namespace std;

vector  < int > suly(1,-1);
vector  < int > os(1,-1);
vector  < bool > level  (100001,true);
set <int> meg;

int main()
{
//    ifstream cin("in.txt");
    long long int n;
    cin>>n;
    int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        suly.push_back(x);
    }
    os.push_back(0);
    for(int i=2;i<=n;i++)
    {
        cin>>x;
        os.push_back(x);
        level[x]=false;
    }
    int ert=0;
    int ind;

    for(int i=n;i>=2;i--)
        {
            ind=i;

            while(level[ind] && os[i]==os[ind])
            {
//                cout<<os[ind]<<" ";
                ert+=suly[ind];
//                cout<<ind<<" ";
                ind--;

            }

            if(ert>suly[os[i]])
                {
                    suly[os[i]]=ert;
//                    cout<<ind<<" "<<suly[i]<<endl;
                }
            level[os[i]]=true;
//            cout<<os[i]<<" "<<suly[os[i]]<<endl;

            i=ind;
            i++;
            ert=0;
        }
    cout<<suly[1];
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Wrong answer0/03ms1824 KiB
2Wrong answer0/03ms2196 KiB
3Partially correct2/43ms2312 KiB
4Partially correct2/43ms2528 KiB
5Partially correct2/43ms2680 KiB
6Wrong answer0/43ms2792 KiB
7Wrong answer0/432ms4112 KiB
8Wrong answer0/639ms4200 KiB
9Wrong answer0/645ms5020 KiB
10Wrong answer0/650ms5152 KiB
11Wrong answer0/674ms5344 KiB
12Wrong answer0/681ms5424 KiB