#BS0000473. Hoàn thiện đồ thị (Complete The Graph)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 , preserving all known weights. Require the shortest distance from to to equal , or report impossibility.
Input
Read , then triples . Vertices are numbered from zero.
Output
Print NO if impossible. Otherwise print YES and 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 . Any valid assignment is accepted.
Subtasks
Subtask 1 (20 points)
- ,
- , , , , ; no parallel edges; all data are integers.
Subtask 2 (30 points)
- ,
- , , , , ; no parallel edges; all data are integers.
Subtask 3 (50 points)
- ,
- , , , , ; 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.