/*
// Definition for Employee.
class Employee {
public int id;
public int importance;
public List<Integer> subordinates;
};
*/classSolution{int sum;int count=1;
List<List<Integer>> ID =newArrayList<>();publicintgetImportance(List<Employee> employees,int id){for(Employee e : employees){if(e.id == id){
sum+=e.importance;
ID.add(e.subordinates);if(ID.size()!=0){DFS(employees,ID.get(0));}break;}}return sum;}publicvoidDFS(List<Employee> employees,List<Integer> id){
System.out.println(id);if(id.size()!=0){for(int i =0; i < id.size(); i++){for(int j =0; j < employees.size(); j++){if(employees.get(j).id == id.get(i)){
sum+=employees.get(j).importance;
ID.add(employees.get(j).subordinates);DFS(employees,ID.get(count++));break;}}}}}}
LeetCode -----690一·解决方法就是递归与回溯 //先介绍一个并未进行算法优化的解法/*// Definition for Employee.class Employee { public int id; public int importance; public List<Integer> subordinates;};*/class Solution { int k; int sum; int coun