問題一覧 > 通常問題

No.1382 Travel in Mitaru city

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 79
作問者 : 蜜蜂 / テスター : cardano1016 Mitarushi
お気に入りにしたユーザー ProblemId : 5869 / 自分の提出
問題文最終更新日: 2021-03-23 18:34:48
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
灘高入試コンテスト2021 (順位表) の他の問題:

Problem Statement

Mitaru City has $\ N\ $ towns and $\ M\ $ roads.
The $i\ $-th town $\ (1\leq i\leq N)\ $ has $\ p_i\ $ residents.
The $\ i\ $-th road $\ (1\leq i\leq M)\ $ bidirectionally connects the $\ a_i\ $-th town and the $\ b_i\ $-th town.
It is guaranteed that for any pair of $\ 2\ $ towns, at most $\ 1\ $ road directly connects them.

You have variables $\ X,Y\ $ and are initially in town $\ S\ $. In the initial state, $\ X=p_S,Y=0\ $ holds.

From now on, you repeat the following action.

    Choose $\ 1\ $ town directly connected by a road to the town you are currently in, and go to that town. Letting that town be the $\ i\ $-th town, if $\ X>p_i\ $, set $\ X=p_i\ $ and add $\ 1\ $ to $\ Y\ $.
When you are in the $\ T\ $-th town, you may end this action. (You may also choose not to end it.)

When you act appropriately so that $\ Y\ $ at the time of ending the operation is maximized and then end the operation, find the value of $\ Y\ $ at the time of ending the operation.

Input

$N\ \ M\ \ S\ \ T$
$p_1\ \ p_2\ \ \cdots p_N$
$a_1\ \ b_1$
$a_2\ \ b_2$
$\vdots$
$a_M\ \ b_M$

  • $2 \leq N \leq 10^5$
  • $1 \leq M \leq 10^5$
  • $1 \leq S,T \leq N$
  • $S \neq T$
  • $1 \leq p_i \leq 10^9(1 \leq i \leq N)$
  • $1 \leq a_i < b_i \leq N(1 \leq i \leq M)$
  • $(a_i,b_i) \neq (a_j,b_j) (i \neq j)$
  • All inputs are integers.
  • It is guaranteed that from $S\ $ you can reach $\ T\ $ by traversing some roads.

Output

When you act appropriately so that $\ Y\ $ at the time of ending the operation is maximized and then end the operation, output the value of $\ Y\ $ at the time of ending the operation, followed by a newline.

Sample

Sample 1
Input
4 4 3 4
8 3 5 2
1 4
2 3
1 2
3 4
Output
2

If you move through towns in the order $\ 3,2,1,4\ $, then $\ X\ $ changes as $\ 5,3,3,2\ $, so $\ Y=2\ $.
There is no way of moving such that $\ Y\ $ becomes $\ 3\ $ or more, so the answer is $2$.

Sample 2
Input
2 1 1 2
1 2021
1 2
Output
0

Since $\ X=1\ $ always holds, $\ Y=0\ $ always holds.

Sample 3
Input
7 8 3 7
12 23 34 45 56 67 78
1 4
2 3
4 7
5 6
2 7
6 7
1 5
2 5
Output
2

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。