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

#BF0000052. Bò đi tham quan (Sightseeing Cows)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bò đi tham quan (Sightseeing Cows)

Sightseeing Cows

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

There are LL landmarks, each worth fun FiF_i, and PP directed paths of travel time TT. The cows must make a closed tour visiting at least two distinct landmarks. Maximize total fun on a cycle divided by total travel time; print 0 when no valid tour exists.

Input

First line L,PL,P; then LL fun values FiF_i, then PP directed edges u,v,Tu,v,T.

Output

Print the best ratio to two decimals by truncation (do not round); if no valid tour exists print 0.

Subtasks

  • Subtask 1 (20 points): 2≤L≤122\le L\le12, 2≤P≤402\le P\le40; 1≤Fi≤10001\le F_i\le1000; 1≤u,v≤L1\le u,v\le L, u≠vu\ne v; 1≤T≤10001\le T\le1000.
  • Subtask 2 (30 points): 2≤L≤1202\le L\le120, 2≤P≤5002\le P\le500; 1≤Fi≤10001\le F_i\le1000; 1≤u,v≤L1\le u,v\le L, u≠vu\ne v; 1≤T≤10001\le T\le1000.
  • Subtask 3 (50 points): 2≤L≤10002\le L\le1000, 2≤P≤50002\le P\le5000; 1≤Fi≤10001\le F_i\le1000; 1≤u,v≤L1\le u,v\le L, u≠vu\ne v; 1≤T≤10001\le T\le1000.

Examples

Input

5 7
30
10
10
5
10
1 2 3
2 3 2
3 4 5
3 5 2
4 5 5
5 1 3
5 2 2

Output

6.00

Explanation

Cycle 1→2→3→5→11\to2\to3\to5\to1 accumulates fun 30+10+10+10=6030+10+10+10=60 and travel time 3+2+2+3=103+2+2+3=10, giving ratio 66. No other cycle has a greater ratio, so the answer is 6.00.