4871 2023. 04. 05 12:05:39 tamasmark Tevefarm cpp17 Elfogadva 50/50 108ms 15228 KiB
// tevefarm.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

ll n, i, m, a, b;
struct adat
{
    bool lat,ok;
    ll db;
    vector<ll>sz;
};
vector<adat>x;
deque<ll>megold;
ll melysegi(ll csp)
{
    ll maxi = 0;
    if (!x[csp].sz.empty())
    {
        for (auto& e : x[csp].sz)
        {
            maxi+=melysegi(e);
        }
        if (x[csp].db >= maxi)
        {
            x[csp].ok = true;
            return x[csp].db;
        }
        else return maxi;
    }
    else
    {
        x[csp].ok = true;
        return x[csp].db;
    }
}
void rekur(ll csp)
{
    if (x[csp].ok)
    {
        megold.push_back(csp);
    }
    else
    {
        for (auto& e : x[csp].sz) rekur(e);
    }
}
int main()
{
    cin >> n;
    x.resize(n + 1);
    for (i = 1; i <= n; ++i)
    {
        cin >> x[i].db;
    }
    for (i = 1; i <= n - 1; ++i)
    {
        cin >> a;
        x[a].sz.push_back(i+1);
    }

    cout<<melysegi(1)<<"\n";
    rekur(1);
    cout << megold.size() << "\n";
    sort(megold.begin(), megold.end());
    for (auto& e : megold) cout << e << " ";
    return 0;
}
/*
8
5 5 7 1 2 3 2 4
1
1
2
2
2
3
3

*/
// 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
Részfeladat Összpont Teszt Verdikt Idő Memória
base 50/50
1 Elfogadva 0/0 3ms 1812 KiB
2 Elfogadva 0/0 3ms 2240 KiB
3 Elfogadva 4/4 2ms 2236 KiB
4 Elfogadva 4/4 2ms 2320 KiB
5 Elfogadva 4/4 3ms 2340 KiB
6 Elfogadva 4/4 3ms 2724 KiB
7 Elfogadva 4/4 46ms 9008 KiB
8 Elfogadva 6/6 54ms 10120 KiB
9 Elfogadva 6/6 64ms 11368 KiB
10 Elfogadva 6/6 74ms 12892 KiB
11 Elfogadva 6/6 97ms 14104 KiB
12 Elfogadva 6/6 108ms 15228 KiB