题目链接

题目描述
The kingdom of Hellcife has several cities that are connected by some roads. One day, the king of Hellcife, Bair Jolsonaro, decided to set fire on some of these cities, just for fun. It’s known that the i-th city has a number Ti, indicating that if the fire reaches that city at time X, then at time X+Ti this city will be completely burnt. After a city is completely burnt, the fire begins to spread across all the roads that are connected to this city, with speed of one meter per second.

Your task is simple: you have to find, for each city, the amount of time it takes for the city to be completely burnt, knowing that at time 0 the king Bair Jolsonaro set fire on some cities.

Input
The first line of input contains three numbers N, M and K (1≤N,M,K≤105), indicating the number of cities in Hellcife, the number of roads in Hellcife, and the number of cities Bair Jolsonaro initially set fire, respectively.

Each of the following M lines contains three integers Ai, Bi, and Ci (1≤Ai,Bi≤N, Ai≠Bi, 1≤Ci≤105), indicating that there is a road between cities Ai and Bi with length of Ci meters.

The next line of input contains N numbers Ti (1≤i≤N, 1≤Ti≤105).

The last line of the input contains K numbers Xi (1≤i≤K, 1≤Xi≤N), indicating that the Xi-th city was chosen by Bair Jolsonaro to be set on fire in the beginning.

Output
The output consists of N lines, the i-th of them indicates the amount of time it takes for the i-th city to be completely burnt.

Examples

Input

5 5 1
1 2 1
2 3 4
3 4 5
4 5 10
1 5 13
1 2 3 4 5
1

Output

1
4
11
20
19

Input

5 18 1
1 3 14877
2 1 81271
1 2 50743
5 1 46485
2 5 41563
5 4 72606
1 2 88401
5 3 56633
2 1 25722
3 1 78857
2 3 95527
5 4 66046
1 4 87400
4 2 49102
3 2 3043
5 3 32836
3 2 13703
4 1 86008
31551 94560 84171 16742 55756
2

Output

151833
94560
181774
160404
191879

Input

7 12 2
6 3 61451
3 5 48225
3 6 18732
5 3 86896
1 5 73979
4 3 49294
3 1 2794
1 5 3449
7 2 86351
4 6 59862
2 1 38972
3 7 20293
36685 6614 81280 91835 68491 81662 10505
2 1

Output

36685
6614
120759
261888
108625
221153
103470

分析:多源最短路问题,由于数据较大,图要用链式前向星来存,不熟悉链式前向星可看该博客,用优先队列来存储pair类型数据,pair储存的分别是燃烧到节点的时间以及节点编号。注意用dis[]数组来存燃烧到每个节点的时间时,不能提前初始化为无穷,那样会超时,只能在主函数外定义,这样自动初始为0,然后在优先队列中存的时间为负值。
代码:

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 200010struct node
{int to;int next;int w;
} edge[N];
int head[N];
long long int t[N];
int n,m,k;
int cnt;void init()
{for(int i=1; i<=N; i++){head[i]=-1;}
}
void build(int u,int v,int w)
{edge[cnt].to=v;edge[cnt].w=w;edge[cnt].next=head[u];head[u]=cnt++;
}long long int dis[N];
priority_queue<pair<long long,int>>que;
void dij()
{while(!que.empty()){int now=que.top().second;que.pop();for(int i=head[now];~i;i=edge[i].next){int v=edge[i].to;int w=edge[i].w;if(!dis[v]){dis[v]=t[v]+dis[now]+w;que.push({-dis[v],v});}else{if(dis[v]>t[v]+dis[now]+w){dis[v]=t[v]+dis[now]+w;que.push({-dis[v],v});}}}}
}int main()
{scanf("%d %d %d",&n,&m,&k);init();int u,v,w;while(m--){scanf("%d %d %d",&u,&v,&w);build(u,v,w);build(v,u,w);}for(int i=1; i<=n; i++){scanf("%lld",&t[i]);}int key;for(int i=1; i<=k; i++){scanf("%d",&key);dis[key]=t[key];que.push({-t[key],key});}dij();for(int i=1;i<=n;i++){printf("%lld\n",dis[i]);}return 0;
}

H - Hellcife is on fire Gym - 102448H相关推荐

  1. H - Streets of Working Lanterns Gym - 101149H -括号匹配-栈模拟

    H - Streets of Working Lanterns Gym - 101149H 题意:括号匹配,有很多"?",这些"?"可以凑成任意一种,判断最后能 ...

  2. 2019 ICPC Asia-East Continent Final (EC-final 2019)题解

    2019 ICPC Asia-East Continent Final 题目 A. City C. Dirichlet kkk-th root D. Fire E. Flow H. King M. V ...

  3. OC实例之汽车启动问题

    1.Car.h文件 #import <Foundation/Foundation.h> //如果A类.h引入B类的.h文件,B类.h文件又引入A类的头文件,就会导致头文件循环引入的错误 / ...

  4. 利用js写的见缝插针小游戏

    利用js写的见缝插针小游戏 今天给大家带来的就是一款叫做<见缝插针>的游戏.有空你就往里插,直到你无处可插!看你能过多少关! 游戏截图 失败时 代码如下 js代码 index.js 测试游 ...

  5. C++常用STL容器

    C++常用STL容器 vector 向量容器 二维数组指针.二维向量 pair 对 list 双向列表 map 表 unordered_map 哈希表 set 集合 unordered_set 哈希集 ...

  6. 【java设计】:全民飞机大战小游戏制作

    文章目录 前言 一.全民飞机大战 二.计划安排 三.源码图和类图展示 四.源码展示 Fire类: GameMain类: GamePanel类: Hero类: Image类: PlaySound类: S ...

  7. STM32灭火小车控制系统(来自LLC团队)

    STM32灭火小车控制系统(来自LLC团队) 第1章 绪论 1.1. 灭火小车控制系统的设计背景和意义 1.2. 国内国际研究现状 1.3. 灭火小车控制系统 的目标 第2章 灭火小车控制系统介绍 2 ...

  8. Python父子关系——继承(反恐精英案例,应用与练习)

    1. 继承 1.1 继承的概念 继承描述的是一种类间关系,一个类A从另一个类B获取成员信息,称类A继承自类B. 提供成员信息的类称父类(基类),获取成员信息的类称子类(派生类). 1.2 继承的作用 ...

  9. 论文阅读>烟雾检测:Video-based Smoke Detection Algorithms: A Chronological Survey

    文章目录 原文 ------------------------------------------------ 基于视频的烟雾检测算法:时序调查 摘要 关键词 1 介绍 2 现有的烟雾检测算法 5 ...

  10. H - Message Bomb Gym - 102798H

    H - Message Bomb Gym - 102798H 题意: 有n个团队,m个人,s个操作 操作1:学生x加入y团队 操作2:学生x推出y团队 操作3:学生x在团队y发送一个信号,在团队y内的 ...

最新文章

  1. displaytag 导出
  2. ASP将查询数据导出EXCEL
  3. Python语言学习之字母L开头函数使用集锦:logging日志用法之详细攻略
  4. Spring事务管理器分类
  5. 第一章 概率论的基本概念
  6. 【Pandas】dataframe 设置完全显示所有列
  7. XY路由算法与转弯模型路由算法
  8. 再学 GDI+[22]: TGPLinearGradientBrush - 之一: TLinearGradientMode
  9. 深圳三防手持终端供应商×××
  10. bzoj4355 Play with sequence(吉司机线段树)题解
  11. ubuntu下安装tun模块图文详细教程
  12. 怎么把手机字体改成繁体_如何把手机字体变成繁体 繁体字转换器
  13. android8.0的电池图标,Android 8.0 电池图标 显示分析
  14. 【转】十大顶级奢侈品服装品牌
  15. 【历史上的今天】9 月 11 日:Adobe 公司联合创始人出生;现代游戏机鼻祖诞生;谷歌推出 Android Pay
  16. 服务器中了挖矿病毒的检测及删除方法
  17. 大数据常见术语,你了解多少?
  18. linux dd命令制作软盘,【Linux】dd命令操作磁盘与镜像
  19. 锐捷网络(福州),开发助理实习生面经
  20. 032_smallpdf

热门文章

  1. linux 快照工具,技术预览:CentOS 7中利用Snapper GUI管理系统快照
  2. C#实战004:Excel操作-读取Excel工作簿
  3. 请编程序将china译成密码,密码规律是:用原来的字母后面第4个字母代替原来的字母。例如:字母A后面4个字母为E,因此,China应译为Glmre。
  4. TCP/IP模型背后的内涵(一)
  5. CodeLite 16无法自动代码补全
  6. iOS 给三方日历加上农历
  7. outlook左侧栏隐藏_Outlook 2007待办事项栏中没有全天活动
  8. 差劲的PHP后端开发,【后端开发】Php为什么性能差
  9. 蓝牙BLE协议分析【附代码实例】
  10. HDU - 5651 xiaoxin juju needs help 逆元模板