PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000019. Kẹt xe ở Edgetown (Edgetown’s Traffic Jams)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kẹt xe ở Edgetown (Edgetown’s Traffic Jams)
Edgetown’s Traffic Jams
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Compare an original undirected road network against a proposed directed version, both using unit edges. Accept the proposal only if every new shortest distance is at most times the original shortest distance plus .
Input
, then adjacency-list lines for the original undirected map and for the proposed directed map; each line begins with vertex and lists destinations; then .
Output
Print Yes if all original reachable ordered pairs satisfy the bound, otherwise No.
Subtasks
- Subtask 1 (40 points): ; ; ; .
- Subtask 2 (60 points): ; ; .
Examples
Input
2
1 2
2 1
1 2
2
1 0
Output
No
Explanation
The old network connects and in both directions; the proposed network cannot reach from . The inequality fails.