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

#FW0000022. Du lịch không dừng (Non-Stop Travel)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Du lịch không dừng (Non-Stop Travel)

Non-Stop Travel

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Directed intersections have travel delays. Find a minimum-delay route from ss to tt and output its sequence of vertices. A route is guaranteed to exist.

Input

nn; for each u=1,…,nu=1,\ldots,n, read cuc_u then cuc_u pairs (v,w)(v,w); finally s,ts,t.

Output

Print Path = followed by the vertex sequence, then ; D second delay.

Subtasks

  • Subtask 1 (40 points): n≤7n\le 7; 2≤n≤202\le n\le 20; 0≤cu≤n−10\le c_u\le n-1; 1≤w≤1000001\le w\le 100000; 1≤s,t≤n1\le s,t\le n.
  • Subtask 2 (60 points): 2≤n≤202\le n\le 20; 0≤cu≤n−10\le c_u\le n-1; 1≤w≤1000001\le w\le 100000; 1≤s,t≤n1\le s,t\le n.

Examples

Input

3
2 2 2 3 10
1 3 3
0
1 3

Output

Path = 1 2 3; 5 second delay

Explanation

The route 1→2→31\to2\to3 has delay 2+3=52+3=5, less than the direct route of delay 1010.