#Q83. 「一本通 3.2 练习 7」道路和航线
「一本通 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 towns, numbered from to . These towns are connected by roads (numbered from to ) and routes (numbered from to ). Each road or route connects town to with a cost of .
For roads, , whereas the cost of routes can be quite peculiar— may even be negative. Roads are bidirectional, meaning you can travel from to or from to , both with the same cost . However, routes are different; they are unidirectional, allowing travel only from to .
In fact, due to recent heightened terrorism concerns, certain policies have been implemented to ensure social harmony: if there is a route from to , it is guaranteed that there is no path (via any combination of roads and routes) from back to . 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 to each town or determine if it's impossible.
Input Format
The first line contains four space-separated integers: ;
The next lines each contain three space-separated integers (representing a road): , and ;
The following lines each contain three space-separated integers (representing a route): , and .
Output Format
Output lines, where the -th line indicates the minimum cost to reach town . If it is impossible, output NO PATH.
Sample 1
There are six towns in total. Roads exist between towns and , and , and and , with costs respectively. Additionally, there are three routes: , , and , with costs respectively. FJ's central town is town . FJ's cows start at town and can reach town via roads. Then, they can take routes to towns and . However, it is impossible to reach towns and .
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, , and for all routes, .