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

#BS0000445. Di chuyển đồng xu trên đồ thị (Toss a Coin to Your Graph...)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Di chuyển đồng xu trên đồ thị (Toss a Coin to Your Graph...)

Toss a Coin to Your Graph...

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Masha has a directed graph with nn vertices numbered from 11 to nn and mm edges. Vertex ii bears a positive integer aia_i.

She places a coin on any vertex and records its value. Each subsequent move follows a directed edge u→vu\to v from her current vertex and records ava_v. Vertices may be visited repeatedly, recording their values on every visit.

She must make exactly k−1k-1 moves, recording exactly kk numbers. Find the smallest possible maximum among the recorded numbers.

Input

  • The first line contains integers n,m,kn,m,k: the vertex count, edge count and number of values to record.
  • The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, the vertex values in order.
  • Each of the next mm lines contains integers uj,vju_j,v_j, denoting a directed edge from uju_j to vjv_j.

Output

Print one integer: the smallest attainable maximum, or -1 if the required number of moves is impossible.

Subtasks

  • Subtask 1 (20 points): 1≤n≤501\le n\le 50; 0≤m≤2000\le m\le 200; 1≤k≤201\le k\le 20; 1≤ai≤1091\le a_i\le10^9; 1≤uj,vj≤n1\le u_j,v_j\le n, uj≠vju_j\ne v_j; for all 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m; no repeated ordered pairs of endpoints.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 0≤m≤20000\le m\le 2000; 1≤k≤10181\le k\le 10^{18}; 1≤ai≤1091\le a_i\le10^9; 1≤uj,vj≤n1\le u_j,v_j\le n, uj≠vju_j\ne v_j; for all 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m; no repeated ordered pairs of endpoints.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 0≤m≤2000000\le m\le 200000; 1≤k≤10181\le k\le 10^{18}; 1≤ai≤1091\le a_i\le10^9; 1≤uj,vj≤n1\le u_j,v_j\le n, uj≠vju_j\ne v_j; for all 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m; no repeated ordered pairs of endpoints.

Examples

Graph in examples 1 and 2

Example 1

Input

6 7 4
1 10 2 3 4 5
1 2
1 3
3 4
4 5
5 6
6 2
2 5

Output

4

Explanation

Follow 1→3→4→51\to3\to4\to5, recording 1,2,3,41,2,3,4. With threshold 3, only vertices 1, 3, 4 remain, forming a chain of at most three vertices, insufficient for four records. Thus 4 is optimal.

Example 2

Input

6 7 100
1 10 2 3 4 5
1 2
1 3
3 4
4 5
5 6
6 2
2 5

Output

10

Explanation

Repeat 2→5→6→22\to5\to6\to2 for 33 rounds, making 99 moves. The maximum is 10. Below 10, vertex 2 is unavailable and the remaining chain 1→3→4→5→61\to3\to4\to5\to6 has at most five vertices, insufficient for 100 records.

Example 3

Input

2 1 5
1 1
1 2

Output

-1

Explanation

The only edge is from 1 to 2, allowing at most one move instead of four.

Example 4

Input

1 0 1
1000000000

Output

1000000000

Explanation

Only one value is required, with no moves. The sole vertex has value 10910^9.