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

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

1 lộ trình

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 AA times the original shortest distance plus BB.

Input

nn, then nn adjacency-list lines for the original undirected map and nn for the proposed directed map; each line begins with vertex uu and lists destinations; then A,BA,B.

Output

Print Yes if all original reachable ordered pairs satisfy the bound, otherwise No.

Subtasks

  • Subtask 1 (40 points): n≤9n\le 9; 1≤n≤1001\le n\le 100; 0≤A,B≤100\le A,B\le 10; 1≤u,v≤n1\le u,v\le n.
  • Subtask 2 (60 points): 1≤n≤1001\le n\le 100; 0≤A,B≤100\le A,B\le 10; 1≤u,v≤n1\le u,v\le n.

Examples

Input

2
1 2
2 1
1 2
2
1 0

Output

No

Explanation

The old network connects 11 and 22 in both directions; the proposed network cannot reach 11 from 22. The inequality fails.