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

#BF0000023. Nỗi lo của Omin-sik (Omin-sik’s Worry)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Nỗi lo của Omin-sik (Omin-sik’s Worry)

Omin-sik's Worry

Source: BOJ

Version: Phuoc Hung OJ Extended

Problem Statement

A traveling salesman travels from city SS to city EE among NN cities numbered from 00. Each directed route costs a nonnegative amount cc. Every visit to city vv earns pvp_v money, including the initial visit to the starting city. Cities and routes may be revisited. Find the maximum cash upon reaching city EE, which can be negative. Print gg if unreachable or Gee if unbounded above.

Input

The first line has N,S,E,MN,S,E,M. Then MM lines u,v,cu,v,c, followed by NN city earnings p0,p1,…,pN−1p_0,p_1,\ldots,p_{N-1}.

Output

Print gg if the destination is unreachable, Gee if profit is unbounded, or the finite maximum money.

Subtasks

  • Subtask 1 (20 points): 2≤N≤122\le N\le12; 0≤M≤200\le M\le20; 0≤c,pi≤1000\le c,p_i\le100; 0≤S,E,u,v<N0\le S,E,u,v<N; directed edges may be repeated.

  • Subtask 2 (30 points): 2≤N≤402\le N\le40; 0≤M≤600\le M\le60; 0≤c,pi≤100000\le c,p_i\le10000; 0≤S,E,u,v<N0\le S,E,u,v<N; directed edges may be repeated.

  • Subtask 3 (50 points): 2≤N≤1002\le N\le100; 0≤M≤1000\le M\le100; 0≤c,pi≤10000000\le c,p_i\le1000000; 0≤S,E,u,v<N0\le S,E,u,v<N; directed edges may be repeated.

Examples

Input

5 0 4 7
0 1 13
1 2 17
2 4 20
0 3 22
1 3 4747
2 0 10
3 4 10
0 0 0 0 0

Output

-32

Explanation

No city pays any earnings. The cheapest route is 0→3→40\to3\to4, costing 22+10=3222+10=32, so final cash is −32-32.