#P6005. [USACO20JAN] Time is Mooney G

[USACO20JAN] Time is Mooney G

Problem Description

Bessie is planning a business trip to Cow-nia, which has NN cities (2N10002 \leq N \leq 1000) numbered 1N1 \ldots N, connected by MM (1M20001 \leq M \leq 2000) one-way roads. Each time Bessie visits city ii, she can earn mim_i Mooney (0mi10000 \leq m_i \leq 1000). Starting from city 11, Bessie wants to earn as much Mooney as possible and finally return to city 11. To avoid disputes, m1=0m_1=0.

Traveling along a road between two cities takes one day. Preparing for the trip is very expensive; traveling for TT days costs C×T2C \times T^2 Mooney (1C10001 \leq C \leq 1000).

What is the maximum amount of Mooney Bessie can earn in one trip? Note that the best plan might be that Bessie does not visit any city other than city 11; in this case, the answer should be 00.

Input Format

The first line contains three integers NN, MM, and CC.

The second line contains NN integers m1,m2,,mNm_1,m_2,\ldots, m_N.

Each of the next MM lines contains two space-separated integers aa and bb (aba \neq b), indicating a one-way road from city aa to city bb.

Output Format

Output one line containing the required answer.

3 3 1
0 10 20
1 2
2 3
3 1
24

Hint

The best travel plan is 12312311 \to 2 \to 3 \to 1 \to 2 \to 3 \to1. Bessie earns a total of 10+20+10+201×62=2410+20+10+20-1 \times 6^2=24 Mooney.

Translated by ChatGPT 5