4674 | 2023. 03. 30 20:41:03 | ZsofiaKeresztely | Tevefarm | cpp14 | Elfogadva 50/50 | 104ms | 13420 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int> > g;
vector<ll> camel;
vector<bool> chosen;
vector<int> op;
ll dfs(int v){
ll r = 0;
for (int x : g[v]){
r += dfs(x);
}
if (camel[v] > r){
r = camel[v];
chosen[v] = true;
}
return r;
}
void dfs2(int v){
if (chosen[v]){
op.push_back(v);
return;
}
for (int x : g[v]){
dfs2(x);
}
}
int main()
{
int n;
cin >> n;
g.resize(n+1);
camel.resize(n+1);
chosen.assign(n+1, 0);
for (int i=1; i<=n; i++){
cin >> camel[i];
}
for (int i=2; i<=n; i++){
int a;
cin >> a;
g[a].push_back(i);
}
cout << dfs(1) << "\n";
dfs2(1);
cout << op.size() << "\n";
for (int x : op){
cout << x << " ";
}
return 0;
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
base | 50/50 | ||||||
1 | Elfogadva | 0/0 | 3ms | 1748 KiB | |||
2 | Elfogadva | 0/0 | 3ms | 2088 KiB | |||
3 | Elfogadva | 4/4 | 3ms | 2124 KiB | |||
4 | Elfogadva | 4/4 | 3ms | 2336 KiB | |||
5 | Elfogadva | 4/4 | 3ms | 2600 KiB | |||
6 | Elfogadva | 4/4 | 3ms | 2940 KiB | |||
7 | Elfogadva | 4/4 | 43ms | 7948 KiB | |||
8 | Elfogadva | 6/6 | 50ms | 8936 KiB | |||
9 | Elfogadva | 6/6 | 59ms | 10304 KiB | |||
10 | Elfogadva | 6/6 | 68ms | 11208 KiB | |||
11 | Elfogadva | 6/6 | 92ms | 12176 KiB | |||
12 | Elfogadva | 6/6 | 104ms | 13420 KiB |