logo AlgoBeat OnlineJudge
登录 注册

#217588. [ICPC 2019 Yinchuan R] Delivery Route

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Pony is the boss of a courier company. The company needs to deliver packages to offices numbered from to . Especially, the -th office is the transfer station of the courier company.

There are ordinary two-way roads and one-way roads between these offices. The delivery vans will consume power if they pass through the -th road. In general, the power consumption on one road must be non-negative. However, thanks to the experimental charging rail, the consumption may be negative on some one-way roads.

Besides, Pony got the following public information. The relevant department promised that if there is a one-way street from to , it is impossible to return from to .

To avoid the delivery vans anchoring on the road, Xiaodao wants to find these lowest power consumptions from the transfer station to these offices.

输入格式

The first line contains four integers , and . This is followed by lines, each line of which contains three integer and describing the roads. The first given roads are ordinary two-way roads, and the last given roads are one-way roads.

输出格式

The output should contain lines, the -th line represents the minimum energy consumption from -th to the -th office if possible, or output NO PATH if it is impossible to reach the -th office.

样例

样例输入 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