This page is still under construction.

Parts of this page are still being built. What you see may change.

Execution Time

Time limit2sMemory limit1024 MB

Summary
In a DAG where tasks run in parallel and each waits for all predecessors, choose exactly K tasks (excluding the first and last) to zero out so the total finish time is minimized.
Level

Medium7 of 10

Topics
Dynamic programming, Topological sort, Greedy, Graph
Solved
No attempts yet

Problem

You developed a program that runs NN tasks in parallel. The NN tasks all have different execution times, and the tasks are ordered.

When a task finishes, it signals the next tasks. A task that receives a signal can run only after it has received signals from all of its preceding tasks.

As in the figure above, there are tasks AA, BB, CC, DD, EE and their order is fixed. We first run task AA and continue through task EE. There is always exactly one task that must start first, like task AA, and exactly one task that runs last, like task EE.

Suppose the execution times of tasks AA through EE are 1 second, 2 seconds, 3 seconds, 2 seconds, 1 second, in that order. The five tasks run as follows.

  • Time 0: first, task AA runs.
  • Time 1: after running for 1 second, task AA signals tasks BB, CC, DD that it has finished.
  • Time 1: tasks BB, CC, DD receive the signals, satisfy their run condition, and start at the same time.
  • Time 3: tasks BB and DD have execution time 2 seconds, so 2 seconds later they signal the next task, task EE.
  • Time 3: task EE receives the signals but has not received a signal from task CC among its preceding tasks, so it waits.
  • Time 4: task CC has execution time 3 seconds, so 3 seconds after task CC starts it signals task EE.
  • Time 4: task EE has received all signals, so it runs. Task EE has execution time 1 second.
  • Time 5: task EE finishes, and the execution of all tasks ends.

Therefore, task EE finishes 5 seconds later.

However, it was confirmed that in this program, forcibly changing the execution times of exactly KK of the remaining N−2N-2 tasks, excluding the task that must start first and the task that runs last, to 0 seconds causes no problem in the program.

Find the minimum time needed for all tasks to complete when the execution times of exactly KK tasks are forcibly changed to 0 seconds.

Input

The number of tasks NN, the number of task-order relations MM, and the number of tasks whose execution time may be forcibly changed to 0 seconds, KK, are given, separated by spaces. A task-order relation tells which task runs after a task finishes.

The second line gives the execution times of the NN tasks, separated by spaces.

From the third line to line M+2M + 2, task-order information is given. Each piece of information consists of two integers SS, EE separated by a space, meaning that task EE runs after task SS finishes.

The starting task number is always 1, and running this task guarantees that all tasks run.

Given tasks AA, BB, CC, the task order is guaranteed not to contain a cycle such as A→B→C→AA \rightarrow B \rightarrow C \rightarrow A.

Output

Print the minimum time needed for all tasks to complete when the execution times of exactly KK tasks are changed to 0 seconds.

Constraints

  • 2≤N≤1002 \le N \le 100
  • N−1≤M≤500N - 1 \le M \le 500
  • 0≤K≤min(N−2,3)0 \le K \le min(N - 2, 3)
  • 1≤S,E≤N1 \le S, E \le N
  • 1≤1 \le execution time ≤1,000,000\le 1,000,000, execution time is an integer

Examples2

  1. Example 1

    Input
    5 6 1
    1 2 3 2 1
    1 2
    1 3
    1 4
    2 5
    3 5
    4 5
    
    Expected output
    4
    
  2. Example 2

    Input
    5 6 0
    1 2 3 2 1
    1 2
    1 3
    1 4
    2 5
    3 5
    4 5
    
    Expected output
    5