vector
struct node {
int node_me;
int num_childnode;
int node_value;
vector
void DFS(int v) { cout << v << endl; actValue += node_vec[v].node_value; if (actValue>maxValue){ maxValue = actValue; } for (int w = 0; w < 10; w++){ if (map[v][w]!=0) DFS(w); } actValue -= node_vec[v].node_value; }
int main() { int num_node = 0; while (cin>>num_node){ struct node node_temp; int temp; for (int i = 0; i < num_node; i++){ cin >> temp; node_temp.node_me = i; node_temp.num_childnode = temp; node_vec.push_back(node_temp); } for (int i = 0; i < num_node; i++){ cin >> temp; cin >> temp; node_vec[i].node_value = temp; for (int j = 0; j < node_vec[i].num_childnode; j++){ cin >> temp; node_vec[i].node_child.push_back(temp); map[i][temp - 1] = 1; } }
DFS(node_vec[0].node_me);
cout << maxValue << endl;
}
} ```