#P10110. [GESP202312 七级] 商品交易

[GESP202312 七级] 商品交易

Background

Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1139.

Problem Description

There are NN types of commodities in the market, numbered from 00 to N−1N-1. The value of commodity ii is viv_i yuan.

There are MM merchants, numbered from 00 to M−1M-1. At merchant jj, you can trade the commodity xjx_j you have for the commodity yjy_j the merchant has. Each merchant trades based on the commodity values. Specifically, if vxj>vyjv_{x_j} > v_{y_j}, the merchant will pay you (vxj−vyj)(v_{x_j} - v_{y_j}) yuan; otherwise, you need to pay the merchant (vyj−vxj)(v_{y_j} - v_{x_j}) yuan. In addition, for each trade the merchant charges a fee of 11 yuan, no matter which commodity is more valuable.

You currently have commodity aa and want to obtain commodity bb through some trades. What is the minimum amount of money you need to spend? (This minimum cost can be negative, meaning you can earn some money while achieving the goal.)

Input Format

The first line contains four integers N,M,a,bN, M, a, b, representing the number of commodities, the number of merchants, the commodity you currently have, and the commodity you want to obtain. It is guaranteed that 0≤a,b<N0 \le a, b < N, and a≠ba \ne b.

The second line contains NN positive integers v0,v1,…,vN−1v_0, v_1, …, v_{N-1} separated by single spaces, representing the value of each commodity. It is guaranteed that 1≤vi≤1091 \le v_i \le 10^9.

The next MM lines each contain two integers xj,yjx_j, y_j, meaning that at merchant jj, you can trade commodity xjx_j for commodity yjy_j. It is guaranteed that 0≤xj,yj<N0 \le x_j, y_j < N, and xj≠yjx_j \ne y_j.

Output Format

Output one integer on a single line, representing the minimum cost. In particular, if it is impossible to obtain commodity bb through trades, output No solution.

3 5 0 2
1 2 4
1 0
2 0
0 1
2 1
1 2
5
3 3 0 2
100 2 4
0 1
1 2
0 2
-95
4 4 3 0
1 2 3 4
1 0
0 1
3 2
2 3
No solution

Hint

Constraints

For 30%30\% of the testdata, N≤10N \le 10 and M≤20M \le 20.

For 70%70\% of the testdata, N≤103N \le 10^3 and M≤104M \le 10^4.

For 100%100\% of the testdata, N≤105N \le 10^5 and M≤2×105M \le 2 \times 10^5.

Translated by ChatGPT 5