#AW342. [USACO11JAN] Roads and Planes G

[USACO11JAN] Roads and Planes G

题目描述

Farmer John 正在一个新的销售区域对他的牛奶销售方案进行调查。他想把牛奶送到 TT 个城镇(1≤T≤25,0001 \le T \le 25,000),编号为 11 到 TT。这些城镇之间通过 RR 条道路(1≤R≤50,0001 \le R \le 50,000,编号为 11 到 RR)和 PP 条航线(1≤P≤50,0001 \le P \le 50,000,编号为 11 到 PP)连接。每条道路 ii 或者航线 ii 连接城镇 AiA_i(1≤Ai≤T1 \le A_i \le T)到 BiB_i(1≤Bi≤T1 \le B_i \le T),花费为 CiC_i。

对于道路 0≤Ci≤10,0000 \le C_i \le 10,000;然而航线的花费很神奇,花费 CiC_i 可能是负数(−10,000≤Ci≤10,000-10,000 \le C_i \le 10,000)。道路是双向的,可以从 AiA_i 到 BiB_i,也可以从 BiB_i 到 AiA_i,花费都是 CiC_i。然而航线与之不同,只可以从 AiA_i 到 BiB_i。

事实上,由于最近恐怖主义太嚣张,为了社会和谐,出台了一些政策保证:如果有一条航线可以从 AiA_i 到 BiB_i,那么保证不可能通过一些道路和航线从 BiB_i 回到 AiA_i。由于 FJ 的奶牛世界公认十分给力,他需要运送奶牛到每一个城镇。他想找到从发送中心城镇 SS(1≤S≤T1 \le S \le T)把奶牛送到每个城镇的最便宜的方案,或者知道这是不可能的。

输入格式

共 R+P+1R+P+1 行。

第 11 行:四个整数 T,R,PT,R,P 和 SS,分别表示城镇的数量,道路的数量,航线的数量和中心城镇。

第 22 到 R+1R+1 行:每行三个整数 Ai,BiA_i,B_i 和 CiC_i,描述一条道路。

第 R+2R+2 到 R+P+1R+P+1 行:每行三个整数 Ai,BiA_i,B_i 和 CiC_i,描述一条航线。

输出格式

共 TT 行,第 ii 行输出城市 SS 到城市 ii 的最小花费。如果不能到达,输出 NO PATH。

输入输出样例 #1

输入 #1

6 3 3 4 
1 2 5 
3 4 5 
5 6 10 
3 5 -100 
4 6 -100 
1 3 -10 

输出 #1

NO PATH 
NO PATH 
5 
0 
-95 
-100 

说明/提示

6 towns. There are roads between town 1 and town 2, town 3 and town 4, and town 5 and town 6 with costs 5, 5 and 10; there are planes from town 3 to town 5, from town 4 to town 6, and from town 1 to town 3 with costs -100, - 100 and -10. FJ is based in town 4.

FJ's cows begin at town 4, and can get to town 3 on the road. They can get to towns 5 and 6 using planes from towns 3 and 4. However, there is no way to get to towns 1 and 2, since they cannot go

backwards on the plane from 1 to 3.