CF567E.President and Roads

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Berland has nn cities, the capital is located in city ss , and the historic home town of the President is in city tt ( sts≠t ). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.

Once a year the President visited his historic home town tt , for which his motorcade passes along some path from ss to tt (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from ss to tt , along which he will travel the fastest.

The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer.

输入格式

The first lines contain four integers nn , mm , ss and tt ( 2<=n<=105; 1<=m<=105; 1<=s,t<=n2<=n<=10^{5}; 1<=m<=10^{5}; 1<=s,t<=n ) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town ( sts≠t ).

Next mm lines contain the roads. Each road is given as a group of three integers ai,bi,lia_{i},b_{i},l_{i} ( 1<=ai,bi<=n; aibi; 1<=li<=1061<=a_{i},b_{i}<=n; a_{i}≠b_{i}; 1<=l_{i}<=10^{6} ) — the cities that are connected by the ii -th road and the time needed to ride along it. The road is directed from city aia_{i} to city bib_{i} .

The cities are numbered from 1 to nn . Each pair of cities can have multiple roads between them. It is guaranteed that there is a path from ss to tt along the roads.

输出格式

Print mm lines. The ii -th line should contain information about the ii -th road (the roads are numbered in the order of appearance in the input).

If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).

Otherwise, if the ii -th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing.

If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes).

输入输出样例

  • 输入#1

    6 7 1 6
    1 2 2
    1 3 10
    2 3 7
    2 4 8
    3 5 3
    4 5 2
    5 6 1
    

    输出#1

    YES
    CAN 2
    CAN 1
    CAN 1
    CAN 1
    CAN 1
    YES
    
  • 输入#2

    3 3 1 3
    1 2 10
    2 3 10
    1 3 100
    

    输出#2

    YES
    YES
    CAN 81
    
  • 输入#3

    2 2 1 2
    1 2 1
    1 2 2
    

    输出#3

    YES
    NO
    

说明/提示

The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.

In the first sample president initially may choose one of the two following ways for a ride: 124561→2→4→5→6 or 123561→2→3→5→6 .

首页