45482023-03-29 14:33:35AblablablaTevefarmcpp17Wrong answer 23/5098ms12012 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, string> pis;

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

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";
        vector<int> a;
        for(int i = 0; i < valasz.second.size(); i += 2){
            a.push_back(valasz.second[i] - '0');
        }

        sort(a.begin(), a.end());
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << " ";
        }
    } else{
        cout << teve[0] << "\n";
        cout << "1\n1\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/03ms1812 KiB
2Wrong answer0/03ms2244 KiB
3Accepted4/43ms2268 KiB
4Accepted4/43ms2344 KiB
5Partially correct2/43ms2548 KiB
6Partially correct2/43ms2924 KiB
7Partially correct2/443ms7960 KiB
8Partially correct3/652ms8972 KiB
9Partially correct3/661ms10112 KiB
10Partially correct3/671ms11328 KiB
11Wrong answer0/690ms10840 KiB
12Wrong answer0/698ms12012 KiB