CF567E.President and Roads

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Berland has n cities, the capital is located in city s, and the historic home town of the President is in city t (s ≠ 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 t, for which his motorcade passes along some path from s to t (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from s to t, 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.

Berland 有 nn 座城市,首都位于城市 ss,总统的故乡位于城市 tt(s≠ts \neq t)。城市之间由单向道路连接,每条道路的通行时间均为正整数。

总统每年都会前往其故乡 tt 一次,其车队沿某条从 ss 到 tt 的路径行驶(返程则乘坐私人飞机)。由于总统日理万机,他总是选择从 ss 到 tt 的最短路径(即总通行时间最小的路径)。

道路与铁路部希望针对每一条道路,判断以下两点:

  1. 总统在出行时是否必定经过该道路;
  2. 若否,则能否通过修复该道路,使其必然包含在从首都到总统故乡的最短路径中。显然,道路修复后其通行时间不能小于 11。

Berland 道路与铁路部同其他部门一样,重视预算控制,因此希望知道修复该道路所需的最小代价。此外,该部门也十分注重精确性,因此修复后的道路通行时间必须为正整数。

输入格式

The first lines contain four integers n, m, s and t (2 ≤ n ≤ 105; 1 ≤ m ≤ 105; 1 ≤ s, t ≤ n) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (s ≠ t).

Next m lines contain the roads. Each road is given as a group of three integers a__i, b__i, l__i (1 ≤ a__i, b__i ≤ n; a__i ≠ b__i; 1 ≤ l__i ≤ 106) — the cities that are connected by the i-th road and the time needed to ride along it. The road is directed from city a__i to city b__i.

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

前几行包含四个整数 nn、mm、ss 和 tt(2 ≤ n ≤ 1052 ≤ n ≤ 10^5;1 ≤ m ≤ 1051 ≤ m ≤ 10^5;1 ≤ s, t ≤ n1 ≤ s, t ≤ n),分别表示 Berland 国家的城市数量、道路数量、首都编号以及总统家乡编号(s ≠ ts ≠ t)。

接下来 mm 行描述道路。每条道路由三个整数 aia_i、bib_i、lil_i(1 ≤ ai, bi ≤ n1 ≤ a_i, b_i ≤ n;ai ≠ bia_i ≠ b_i;1 ≤ li ≤ 1061 ≤ l_i ≤ 10^6)组成,表示第 ii 条道路连接的城市及沿该道路行驶所需的时间。该道路为有向边,方向从城市 aia_i 指向城市 bib_i。

城市编号为 11 到 nn。任意两个城市之间可能存在多条道路。保证存在一条从 ss 到 tt 的路径。

输出格式

Print m lines. The i-th line should contain information about the i-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 i-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).

输出 m 行。第 i 行应包含关于第 i 条道路的信息(道路按输入中出现的顺序编号)。

  • 如果总统在出行过程中一定会经过该道路,则该行仅包含一个单词 “YES”(不带引号)。
  • 否则,如果可以对该第 i 条道路进行修复(修复后其通行时间仍为正),使得总统一定会经过它,则输出空格分隔的单词 “CAN”(不带引号)以及修复所需的最小代价。
  • 如果无法通过修复使该道路满足总统一定会经过的条件,则输出 “NO”(不带引号)。

输入输出样例

  • 输入#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: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6.

修复道路的代价是修复前后沿该道路骑行所需时间的差值。

在第一个样例中,总统最初可以选择以下两种骑行路线之一:1 → 2 → 4 → 5 → 6 或 1 → 2 → 3 → 5 → 6。

输入解题思路,AI测评打分。不知道怎么写?

首页