Description

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

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

Examples
Input
5 5 13 0 4
0 1 5
2 1 2
3 2 3
1 4 0
4 3 4
Output
YES
0 1 5
2 1 2
3 2 3
1 4 8
4 3 4
Input
2 1 123456789 0 1
0 1 0
Output
YES
0 1 123456789
Input
2 1 999999999 1 0
0 1 1000000000
Output
NO
Note

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

正解:dijkstra

解题报告:

  其实这道题也很简单,考场上没想出来真是我傻...

  首先那些可以修改的边最小边权为1,则全部改为1,那么如果此时最短路小于等于L,那么至少是有解的。否则无解。

  然后依次修改当前还差的边权,直到合法,反正CF机子快,丝毫不虚。

  然而我WA了一个晚上,因为我的inf设大了,一加就炸,调了很久才发现...

 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int MAXN = ;
const int MAXM = ;
const int MOD = ;
int n,m,L,s,t,ecnt;
int first[MAXN],to[MAXM],next[MAXM],w[MAXM],dis[MAXN];
int tag[MAXM];//!!!!!
int dui[MAXN*],head,tail;
bool in[MAXN],ok; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline void SPFA(){
//memset(dis,63,sizeof(dis));
for(int i=;i<=n;i++) dis[i]=;//不能设太大!!!不然会炸,WA了好久!!!
dis[s]=; head=tail=; dui[++tail]=s; memset(in,,sizeof(in)); in[s]=;
while(head!=tail) {
head%=n; head++; int u=dui[head]; in[u]=;
for(int i=first[u];i>;i=next[i]) {
int v=to[i];
if(dis[v]>dis[u]+w[i]) {
dis[v]=dis[u]+w[i];
if(!in[v]) { tail%=n; tail++; dui[tail]=v; in[v]=; }
}
}
}
} inline void work(){
//memset(first,-1,sizeof(first));
n=getint(); m=getint(); L=getint(); s=getint()+; t=getint()+;
int x,y,z;ecnt=;
for(int i=;i<=m;i++) {
x=getint()+; y=getint()+; z=getint();
next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; w[ecnt]=z; if(z==) tag[ecnt]=,w[ecnt]=;
next[++ecnt]=first[y]; first[y]=ecnt; to[ecnt]=x; w[ecnt]=z; if(z==) tag[ecnt]=,w[ecnt]=;
}
SPFA(); if(dis[t]>L) { printf("NO"); return ; }
ok=false;
for(int i=;i<=n;i++) {
for(int j=first[i];j>;j=next[j]) {
if(j & )
if(tag[j]) {
if(dis[t]==L){ ok=true ; break;}
if(dis[t]<L) {
w[j]=w[j^]=L-dis[t]+;
SPFA();
}
}
}
if(ok) break;
}
if(!ok && dis[t]!=L) { printf("NO"); }
else{
printf("YES\n");
for(int i=;i<=n;i++)
for(int j=first[i];j>;j=next[j])
if(j&)
printf("%d %d %d\n",to[j]-,to[j^]-,w[j]);
}
} int main()
{
work();
return ;
}

最新文章

  1. Spark高级数据分析中文版-读者交流
  2. Webview加载本地js、图片的方法
  3. 读取另一个项目中方法的json
  4. Tsung安装与使用
  5. javascript对象属性的赋值解析
  6. Linux下如何搭建VPN服务器(转)
  7. linux终端快捷键
  8. SDN环境搭建(mininet,OVS,ryu安装及命令)
  9. netty Getting Started--reference
  10. [YZOJ1579]&amp;&amp;[BZOJ2450]arr
  11. ubuntu 14.04 修改PS1提示符
  12. 超级密码(bfs)
  13. HDOJ 2736 Surprising Strings
  14. LNMP的安装
  15. JVM垃圾收集器&amp;对象的引用回收
  16. Java调用第三方http接口的方式
  17. LeetCode算法题-Minimum Index Sum of Two Lists(Java实现)
  18. 常用sql 集合记录整理
  19. 菜鸟初学redis(二)
  20. JNI和NDK

热门文章

  1. Unity原厂讲师大解密
  2. SVN和git的使用(附github的简单玩法)
  3. Netty开发UDP协议
  4. MVC ajaxSubmit上传图片
  5. Android Studio使用中的异常
  6. VisualStudio2013+EF6+MySql5.5环境下配置
  7. [转]2006 MySQL server has gone away错误,最大值溢出解决办法 mysql max_allowed_packet 查询和修改
  8. caffe windows 学习第一步:编译和安装(vs2012+win 64)
  9. beta阶段140字评论
  10. 安装.NET CORE