题目链接:点击打开链接
题意:
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?
The first line contains five integers n, m, L, s, t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 10 000, 1 ≤ L ≤ 109, 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, ui, vi, wi (0 ≤ ui, vi ≤ n - 1, ui ≠ vi, 0 ≤ wi ≤ 109). ui and vi denote the endpoints of the edge and wi denotes its weight. If wi 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.
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 ui, vi and wi, denoting an edge between vertices ui and vi of weight wi. 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 1018.
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.
大意:给你一个无向图n(1000)个点,m条边(10000),起点s,终点t,与两点间最短路距离L。然后再告诉你每条边u,v,w为权值,如果w为0,表示其被擦去,不是真实值,求出w为0时w的真实值的一种图的可能性,使得从s到t最短路为L.
思路:首先,假设w为0的边为可变边,当这些边都大于L的时候,如果此时最短路长度还是小于L,就是不可能的。同理,当边长都为1的时候,如果最短路大于L了,也是不可能的图;于是除了这两种情况后,其他都能通过构造边长来满足最短路长度为L。
但是,这里就有问题了,我之前的做法是把所有可变边的权值赋值为1,然后跑最短路,求出实际最短和理论最短的差值, 再加给其中一个可变边。
然后就gg了。答案不对;
后来才发现 原来如果存在次小路 代码:#include