153872025-02-19 10:45:26zsebiTevefarmcpp17Wrong answer 25/5097ms5932 KiB
// tevefarm.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#define ll long long
using namespace std;
struct adat
{
    ll teve = 0, tmax = 0;
    vector<ll>sz;
};
vector<adat>x;
ll n;
void ltev(ll p)
{
    if (x[p].sz.size() == 0)
    {
        x[p].tmax = x[p].teve;
        return;
    }
    else
    {
        ll s = 0;
        for (auto& e : x[p].sz)
        {
            ltev(e);
            s += x[e].tmax;
        }
        x[p].tmax = max(s, x[p].teve);
    }
    return;
}
int main()
{
    cin >> n;
    x.resize(n + 1);
    for (int i = 1; i <= n; ++i)cin >> x[i].teve;
    for (int i = 2; i <= n; ++i)
    {
        ll a;
        cin >> a;
        x[a].sz.push_back(i);
    }
    ltev(1);
    cout << x[1].tmax;
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base25/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/02ms316 KiB
3Partially correct2/41ms316 KiB
4Partially correct2/41ms316 KiB
5Partially correct2/41ms512 KiB
6Partially correct2/42ms316 KiB
7Partially correct2/439ms3140 KiB
8Partially correct3/650ms3784 KiB
9Partially correct3/656ms4396 KiB
10Partially correct3/667ms4816 KiB
11Partially correct3/689ms5428 KiB
12Partially correct3/697ms5932 KiB