You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.

For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. They have importance value 15, 10 and 5, respectively. Then employee 1 has a data structure like [1, 15, [2]], and employee 2 has [2, 10, [3]], and employee 3 has [3, 5, []]. Note that although employee 3 is also a subordinate of employee 1, the relationship is not direct.

Now given the employee information of a company, and an employee id, you need to return the total importance value of this employee and all his subordinates.

Example 1:

Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1
Output: 11
Explanation:
Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3. They both have importance value 3. So the total importance value of employee 1 is 5 + 3 + 3 = 11.
class Solution {
public:
int getImportance(vector<Employee*> employees, int id) {
unordered_map<int,Employee*> map ;
for (auto e : employees){
map[e->id] = e ;
} return dfs(map , id) ;
} int dfs(unordered_map<int,Employee*> map , int id){
int sum = map[id]->importance ;
for (auto sub_id : map[id]->subordinates){
sum += dfs(map,sub_id) ;
}
return sum ;
}
};

最新文章

  1. ImportError: The _imagingft C module is not installed
  2. python中的GIL(全局解释锁)多线程能够提升效率
  3. 通过声明Attribute属性改变不同类的输出效果
  4. 做NavMesh相关工作时收集的一些文章
  5. Oracle存储过程获取YYYY-MM-DD的时间格式
  6. 重命名计算机名称导致TFS版本管理下的工作区问题的修复
  7. nest &#39;for&#39; loop.
  8. Tomcat6+nginx集群,达到负载均衡和session复制
  9. linux ftp 安装及相关命令
  10. GDOI模拟赛Round 1
  11. 一、初识CocoaPods——XCode的依赖库管理工具
  12. OO第一阶段总(休)结(养)分(生)析(息)
  13. .NET界面控件DevExpress发布v18.2.4|附下载
  14. Python2.7-hmac
  15. 扩展Spring切面
  16. CefSharp,Winform程序中加载web网页
  17. Hadoop生态圈-Hbase过滤器(Filter)
  18. am335x -- kio 控制接口
  19. write 系统调用耗时长的原因
  20. 去除掉myeclipse2017页面右上角的图片

热门文章

  1. PAT 1079 延迟的回文数(代码+思路)
  2. PID算法(C语言)
  3. [Automation] 自动化测试工具和测试框架大集合
  4. 2018.09.26 bzoj5218: [Lydsy2017省队十连测]友好城市(回滚莫队)
  5. 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)
  6. phonegap android插件,启动activity并返回值
  7. python将字典中的数据保存到文件中
  8. MATLAB实现最优低通滤波器的函数
  9. 微信小程序底部导航Tabbar
  10. Airplace平台