151582025-02-14 11:35:57BencuTevefarmcpp17Wrong answer 19/50101ms5332 KiB
#include <bits/stdc++.h>

using namespace std;
int L[100001],n,m,ma,M[100001];
struct Bencu {
    vector<int>fiuk;
    int s=0;
}a[100001];
int maxi (int x) {
    if (a[x].s==0) return L[x];
    else {
    int p=0;
    for (int i=0; i<a[x].s; i++) p=p+maxi(a[x].fiuk[i]);
    if (L[x]>p) return L[x];
    else return p;
    }
}

int main()
{
    ifstream f("be.in");
    cin>>n;
    for (int i=1; i<=n; i++) cin>>L[i];
    for (int i=2; i<=n; i++) {
        int x;
        cin>>x;
        a[x].s++;
        a[x].fiuk.push_back(i);
    }
    cout<<maxi(1);
    /*for (int i=1; i<=n; i++) {
        cout<<i<<": ";
        for (int j=0; j<a[i].s; j++) cout<<a[i].fiuk[j]<<"-"<<maxi(a[i].fiuk[j])<<"  ";
        cout<<endl;
    }*/
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base19/50
1Wrong answer0/04ms3372 KiB
2Wrong answer0/04ms3380 KiB
3Partially correct2/43ms3380 KiB
4Partially correct2/44ms3380 KiB
5Partially correct2/44ms3380 KiB
6Partially correct2/44ms3568 KiB
7Partially correct2/441ms4400 KiB
8Partially correct3/648ms4744 KiB
9Partially correct3/654ms4772 KiB
10Partially correct3/668ms4960 KiB
11Wrong answer0/686ms5176 KiB
12Wrong answer0/6101ms5332 KiB