#Q83. 「一本通 3.2 练习 7」道路和航线

    ID: 2166 Type: Default 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>最短路2011拓扑排序USACO Contest一本通提高

「一本通 3.2 练习 7」道路和航线

Description

Original source: USACO 2011 Jan. Gold

Farmer John is investigating a new sales region for his milk distribution plan. He wants to deliver milk to TT towns, numbered from 11 to TT. These towns are connected by RR roads (numbered from 11 to RR) and PP routes (numbered from 11 to PP). Each road ii or route ii connects town AiA_i to BiB_i with a cost of CiC_i.

For roads, 0Ci1040 \le C_i \le 10^4, whereas the cost of routes can be quite peculiar—CiC_i may even be negative. Roads are bidirectional, meaning you can travel from AiA_i to BiB_i or from BiB_i to AiA_i, both with the same cost CiC_i. However, routes are different; they are unidirectional, allowing travel only from AiA_i to BiB_i.

In fact, due to recent heightened terrorism concerns, certain policies have been implemented to ensure social harmony: if there is a route from AiA_i to BiB_i, it is guaranteed that there is no path (via any combination of roads and routes) from BiB_i back to AiA_i. Since FJ's cows are world-renowned for their reliability, he needs to transport cows to every town. He wants to find the cheapest way to send cows from the central distribution town SS to each town or determine if it's impossible.

Input Format

The first line contains four space-separated integers: T,R,P,ST, R, P, S;

The next RR lines each contain three space-separated integers (representing a road): Ai,BiA_i, B_i, and CiC_i;

The following PP lines each contain three space-separated integers (representing a route): Ai,BiA_i, B_i, and CiC_i.

Output Format

Output TT lines, where the ii-th line indicates the minimum cost to reach town ii. If it is impossible, output NO PATH.

Sample 1

There are six towns in total. Roads exist between towns 11 and 22, 33 and 44, and 55 and 66, with costs 5,5,105, 5, 10 respectively. Additionally, there are three routes: 353\to 5, 464\to 6, and 131\to 3, with costs 100,100,10-100, -100, -10 respectively. FJ's central town is town 44. FJ's cows start at town 44 and can reach town 33 via roads. Then, they can take routes to towns 55 and 66. However, it is impossible to reach towns 11 and 22.

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

NO PATH
NO PATH
5
0
-95
-100

Data Range and Hints

For all data, $1\le T\le 2.5\times 10^4, 1\le R,P\le 5\times 10^4, 1\le A_i,B_i,S\le T$. It is guaranteed that for all roads, 0Ci1040 \le C_i \le 10^4, and for all routes, 104Ci104-10^4 \le C_i \le 10^4.