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

#FW0000009. Chi phí di chuyển (Travelling Cost)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chi phí di chuyển (Travelling Cost)

Travelling Cost

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Locations 00 through 500500 are connected by bidirectional roads with positive costs. Answer shortest costs from one fixed start to multiple destinations.

Input

mm; mm roads u,v,wu, v, w; source ss; qq; then qq destinations.

Output

Print shortest costs, or NO PATH when unreachable.

Subtasks

  • Subtask 1 (40 points): at most 1010 distinct road endpoints; 1≤m≤5001\le m\le 500; 0≤u,v,s≤5000\le u,v,s\le 500; 1≤w≤1001\le w\le 100; 1≤q≤5001\le q\le 500.
  • Subtask 2 (60 points): 1≤m≤5001\le m\le 500; 0≤u,v,s≤5000\le u,v,s\le 500; 1≤w≤1001\le w\le 100; 1≤q≤5001\le q\le 500.

Examples

Input

7
0 1 4
0 3 8
1 4 1
1 2 2
4 2 3
2 5 3
3 4 2
0
4
1
4
5
7

Output

4
5
9
NO PATH

Explanation

From location 0, shortest costs to 1, 4, 5 are respectively 44, 55 and 99. Location 7 cannot be reached.