4685 | 2023-03-31 08:53:13 | Albertstein99 | Tevefarm | cpp17 | Forditási hiba |
#include <bits/Stdc++.h>
using namespace std;
vector <vector <int> > g;
vector <int> W;
vector <bool> Q;
vector <int> ans;
int dfs(int node){
int maxi = 0;
for(auto x : g[node])
maxi += dfs(x);
if(maxi > W[node])
return maxi;
Q[node] = 1;
return W[node];
}
void dfs2(int node){
if(Q[node]){
ans.push_back(node);
return;
}
for(auto x : g[node])
dfs2(x);
}
int main(){
int N;
cin >> N;
W.resize(N + 1);
g.resize(N + 1);
Q.resize(N + 1);
for(int i = 1; i <= N; i++)
cin >> W[i];
for(int i = 2; i <= N; i++){
int x;
cin >> x;
g[x].push_back(i);
}
cout << dfs(1) << '\n';
dfs2(1);
cout << ans.size() << '\n';
for(auto x : ans){
cout << x << ' ';
}
}
exit status 1
main.cpp:1:10: fatal error: bits/Stdc++.h: No such file or directory
1 | #include <bits/Stdc++.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
Exited with error status 1