PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000473. Hoàn thiện đồ thị (Complete The Graph)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hoàn thiện đồ thị (Complete The Graph)

Complete The Graph

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Missing edge weights in a simple undirected graph are encoded as zero. Assign each missing weight a positive integer at most 101810^{18}, preserving all known weights. Require the shortest distance from ss to tt to equal LL, or report impossibility.

Input

Read n,m,L,s,tn,m,L,s,t, then mm triples ui,vi,wiu_i,v_i,w_i. Vertices are numbered from zero.

Output

Print NO if impossible. Otherwise print YES and mm lines with endpoints and final weights. Preserve the original edge set and known weights. Edge order and endpoint orientation may change. New weights must be in [1,1018][1,10^{18}]. Any valid assignment is accepted.

Subtasks

Subtask 1 (20 points)

  • 2≤n≤82\le n\le8, 1≤m≤201\le m\le20
  • 1≤L≤1091\le L\le10^9, 0≤s,t,ui,vi<n0\le s,t,u_i,v_i<n, s≠ts\ne t, ui≠viu_i\ne v_i, 0≤wi≤1090\le w_i\le10^9; no parallel edges; all data are integers.

Subtask 2 (30 points)

  • 2≤n≤1002\le n\le100, 1≤m≤3001\le m\le300
  • 1≤L≤1091\le L\le10^9, 0≤s,t,ui,vi<n0\le s,t,u_i,v_i<n, s≠ts\ne t, ui≠viu_i\ne v_i, 0≤wi≤1090\le w_i\le10^9; no parallel edges; all data are integers.

Subtask 3 (50 points)

  • 2≤n≤10002\le n\le1000, 1≤m≤100001\le m\le10000
  • 1≤L≤1091\le L\le10^9, 0≤s,t,ui,vi<n0\le s,t,u_i,v_i<n, s≠ts\ne t, ui≠viu_i\ne v_i, 0≤wi≤1090\le w_i\le10^9; no parallel edges; all data are integers.

Examples

Example 1

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

Explanation

Set edge 1–4 to 8. Route 0–1–4 has length 13; the route through 2,3 has length 14.

Example 2

Input

2 1 123456789 0 1
0 1 0

Output

YES
0 1 123456789

Explanation

Set the only edge to L.

Example 3

Input

2 1 999999999 1 0
0 1 1000000000

Output

NO

Explanation

The only edge is fixed and longer than L.