아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Back and Forth

시간 제한1초메모리 제한256 MB

요약
역마다 표를 사면 그 역을 몇 번이든 지날 수 있을 때, s에서 t로 갔다가 s로 돌아오는 왕복이 가능하도록 사야 하는 표 가격의 최솟값을 구한다.
난이도

보통10점 중 7점

유형
그래프, 최단 경로, 동적 계획법
정답자
아직 제출이 없습니다

문제

There are nn stations and mm directed roads between them.

One day, Chiaki is going from the ss-th station to the tt-th station, then back to the ss-th station. Doing so, he needs to buy tickets for stations he passes. The price the tickets for the ii-th station is p_ip\_i. If Chiaki buys a ticket for the ii-th station, he can passes the station as many times as he wants. Find the minimum price of tickets to buy.

입력

There are multiple test cases. The first line of the input contains an integer TT (1≤T≤2001 \leq T \leq 200) indicating the number of test cases. For each test case:

The first line of each test case contains four integers nn, mm, ss and tt (1≤n≤2001 \leq n \leq 200, 0≤m≤n×(n−1)0 \leq m \leq n \times (n - 1), 1≤s,t≤n1 \leq s, t \leq n). The second line contains nn integers p_1,p_2,…,p_np\_1, p\_2, \dots, p\_n (1≤p_i≤1001 \leq p\_i \leq 100). The ii-th of the following mm lines contains two integers a_ia\_i and b_ib\_i, which denote a road from the a_ia\_i station to the b_ib\_i-th station (1≤a_i,b_i≤n1 \leq a\_i, b\_i \leq n).

The sum of all nn does not exceed 200200.

출력

For each test case, output an integer denoting the answer. Print −1-1 for no solution.

예제1

  1. 예제 1

    입력
    3
    4 5 1 4
    1 1 1 1
    1 2
    2 3
    3 1
    4 2
    3 4
    4 4 1 2
    1 1 1 1
    1 2
    2 3
    3 4
    4 1
    4 8 1 3
    1 100 1 1
    1 2
    2 1
    2 3
    3 2
    1 4
    4 1
    3 4
    4 3
    
    예상 출력
    4
    4
    3