Huawei_test_4.jpg

  • 信息提取/整理
  • 图的深度优先遍历(无访问记录)

  • 将函数的相互调用用一张图来描述 调用链最大栈区 - 图2```cpp

    include

    include

    using namespace std;

vector node_vec; int map[10][10] = { 0 }; int maxValue = 0; int actValue = 0;

struct node { int node_me; int num_childnode; int node_value; vector node_child; };

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; } }

  1. DFS(node_vec[0].node_me);
  2. cout << maxValue << endl;
  3. }

} ```