#P10110. [GESP202312 七级] 商品交易
[GESP202312 七级] 商品交易
Background
Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1139.
Problem Description
There are types of commodities in the market, numbered from to . The value of commodity is yuan.
There are merchants, numbered from to . At merchant , you can trade the commodity you have for the commodity the merchant has. Each merchant trades based on the commodity values. Specifically, if , the merchant will pay you yuan; otherwise, you need to pay the merchant yuan. In addition, for each trade the merchant charges a fee of yuan, no matter which commodity is more valuable.
You currently have commodity and want to obtain commodity 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 , 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 , and .
The second line contains positive integers separated by single spaces, representing the value of each commodity. It is guaranteed that .
The next lines each contain two integers , meaning that at merchant , you can trade commodity for commodity . It is guaranteed that , and .
Output Format
Output one integer on a single line, representing the minimum cost. In particular, if it is impossible to obtain commodity 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 of the testdata, and .
For of the testdata, and .
For of the testdata, and .
Translated by ChatGPT 5