45472023-03-29 14:19:11AblablablaTevefarmcpp17Wrong answer 21/5094ms11912 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, string> pis;

int n;
vector<int> teve;
vector<vector<int>> elsoVar;
vector<string> utvonalak;

pis vizsgal(int helyzet){

    int osszeg = 0;
    string lehet;

    for(int x : elsoVar[helyzet]){
        pis a = vizsgal(x);
        osszeg += a.first;
        lehet += a.second;
        if(lehet[lehet.size() - 1] != ' '){
            lehet += " ";
        }
    }

    //cout << helyzet << " " << max(osszeg, teve[helyzet]) << "\n";
    pis valasz;
    if(osszeg > teve[helyzet]){
        valasz.first = osszeg;
        valasz.second = lehet;
    } else{
        valasz.first = teve[helyzet];
        valasz.second = char(helyzet + 1) + '0';
    }

    return valasz;
}

int main()
{
    cin >> n;
    teve.assign(n, 0);
    elsoVar.assign(n, vector<int>(0, 0));

    for(int i = 0; i < n; i++){
        cin >> teve[i];
    }

    for(int i = 0; i < n - 1; i++){
        int a;
        cin >> a;
        elsoVar[a - 1].push_back(i + 1);
    }

    /*for(int i = 0; i < n; i++){
        for(int x : elsoVar[i]){
            cout << x << " ";
        }

        cout << "\n";
    }*/

    pis valasz = vizsgal(0);
    if(valasz.first > teve[0]){
        cout << valasz.first << "\n";
        cout << valasz.second.size() / 2 << "\n";
        cout << valasz.second << "\n";
    } else{
        cout << teve[0] << "\n";
        cout << "1\n1\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1688 KiB
2Wrong answer0/03ms2180 KiB
3Accepted4/43ms2164 KiB
4Partially correct2/43ms2312 KiB
5Partially correct2/43ms2396 KiB
6Partially correct2/43ms2680 KiB
7Partially correct2/441ms7220 KiB
8Partially correct3/648ms8360 KiB
9Partially correct3/656ms9272 KiB
10Partially correct3/664ms10328 KiB
11Wrong answer0/685ms10788 KiB
12Wrong answer0/694ms11912 KiB