CF715B.Complete The Graph

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

ZS the Coder has drawn an undirected graph of nn vertices numbered from 00 to n1n-1 and mm edges between them. Each edge of the graph is weighted, each weight is a positive integer.

The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edges which weights were erased, so that the length of the shortest path between vertices ss and tt in the resulting graph is exactly LL . Can you help him?

输入格式

The first line contains five integers n,m,L,s,tn,m,L,s,t ( 2<=n<=1000,1<=m<=10000,1<=L<=109,0<=s,t<=n1,st2<=n<=1000,1<=m<=10000,1<=L<=10^{9},0<=s,t<=n-1,s≠t ) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.

Then, mm lines describing the edges of the graph follow. ii -th of them contains three integers, ui,vi,wiu_{i},v_{i},w_{i} ( 0<=ui,vi<=n1,uivi,0<=wi<=1090<=u_{i},v_{i}<=n-1,u_{i}≠v_{i},0<=w_{i}<=10^{9} ). uiu_{i} and viv_{i} denote the endpoints of the edge and wiw_{i} denotes its weight. If wiw_{i} is equal to 00 then the weight of the corresponding edge was erased.

It is guaranteed that there is at most one edge between any pair of vertices.

输出格式

Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.

Otherwise, print "YES" in the first line. Next mm lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. ii -th of them should contain three integers uiu_{i} , viv_{i} and wiw_{i} , denoting an edge between vertices uiu_{i} and viv_{i} of weight wiw_{i} . The edges of the new graph must coincide with the ones in the graph from the input. The weights that were not erased must remain unchanged whereas the new weights can be any positive integer not exceeding 101810^{18} .

The order of the edges in the output doesn't matter. The length of the shortest path between ss and tt must be equal to LL .

If there are multiple solutions, print any of them.

输入输出样例

  • 输入#1

    5 5 13 0 4
    0 1 5
    2 1 2
    3 2 3
    1 4 0
    4 3 4
    

    输出#1

    YES
    0 1 5
    2 1 2
    3 2 3
    1 4 8
    4 3 4
    
  • 输入#2

    2 1 123456789 0 1
    0 1 0
    

    输出#2

    YES
    0 1 123456789
    
  • 输入#3

    2 1 999999999 1 0
    0 1 1000000000
    

    输出#3

    NO
    

说明/提示

Here's how the graph in the first sample case looks like :

In the first sample case, there is only one missing edge weight. Placing the weight of 88 gives a shortest path from 00 to 44 of length 1313 .

In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456789123456789 .

In the last sample case, there is no weights to assign but the length of the shortest path doesn't match the required value, so the answer is "NO".

首页