Codeforces Round 372 (Div. 1)
B
Complete The Graph
Codeforces
2300
原题
← AC →
翻译中…

ZS the Coder has drawn an undirected graph of $*n*$ vertices numbered from $0$ to $*n* - 1$ and $*m*$ 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 $*s*$ and $*t*$ in the resulting graph is exactly $*L*$. Can you help him?

翻译中…

Input

翻译中…

The first line contains five integers $*n*, *m*, *L*, *s*, *t*$ ($2 ≤ *n* ≤ 1000,  1 ≤ *m* ≤ 10 000,  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, $*m*$ lines describing the edges of the graph follow. $*i*$-th of them contains three integers, $*u*_{*i*}, *v*_{*i*}, *w*_{*i*}$ ($0 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n* - 1,  *u*_{*i*} ≠ *v*_{*i*},  0 ≤ *w*_{*i*} ≤ 10^{9}$). $*u*_{*i*}$ and $*v*_{*i*}$ denote the endpoints of the edge and $*w*_{*i*}$ denotes its weight. If $*w*_{*i*}$ is equal to $0$ then the weight of the corresponding edge was erased.

翻译中…

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

翻译中…

Output

翻译中…

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 $*m*$ lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. $*i*$-th of them should contain three integers $*u*_{*i*}$, $*v*_{*i*}$ and $*w*_{*i*}$, denoting an edge between vertices $*u*_{*i*}$ and $*v*_{*i*}$ of weight $*w*_{*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 $10^{18}$.

翻译中…

The order of the edges in the output doesn't matter. The length of the shortest path between $*s*$ and $*t*$ must be equal to $*L*$.

翻译中…

If there are multiple solutions, print any of them.

翻译中…

Note

翻译中…

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

翻译中…

image

翻译中…

In the first sample case, there is only one missing edge weight. Placing the weight of $8$ gives a shortest path from $0$ to $4$ of length $13$.

翻译中…

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

翻译中…

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".

翻译中…

样例

Input #1
5 5 13 0 4
0 1 5
2 1 2
3 2 3
1 4 0
4 3 4
Output #1
YES
0 1 5
2 1 2
3 2 3
1 4 8
4 3 4
InputCopy OutputCopy
Input #2
2 1 123456789 0 1
0 1 0
Output #2
YES
0 1 123456789
InputCopy OutputCopy
Input #3
2 1 999999999 1 0
0 1 1000000000
Output #3
NO
InputCopy OutputCopy
题目信息
题号
715B
时间限制
4 s
内存限制
256 MB
标签
二分
构造
图论
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。