시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB211100.000%

문제

There are $N$ cities on some Japanese island and $M$ one-directional roads connecting those cities. Each city has a museum which is open at even days and is closed at odd days. Museum of $i$-th city holds $w_i$ Hokusai artworks.

Bytika arrived on the main city of the island (whis is placed at city 0) at the morning of an even day. Each day, she visits the museum in the current city (if the museum is open on that day and if she did not visit this museum before), and moves overnight to another city (possibly one she already visited) by using any one road leading from the current city. If Bytika cannot leave the current city, or if here are no chances to see new Hokusai artworks, she leaves the island by plane.

Find the maximum number of Hokusai artworks Bytika can see.

입력

The first line of input contains two integers $n$ and $m$ ($1 \le n \le 10^5$, $0 \le m \le \min (n \cdot (n - 1), 10^5)$): the number of cities and the number of roads. The second line contains $n$ integers $w_0$, $w_1$, $\ldots$, $w_{n - 1}$; $i$-th of those integers is the number of Hokusai artworks in the museum of $i$-th city ($0 \le w_i \le 1000$). Each of next $m$ lines contains two integers $s_j$ and $t_j$ denoting that there is a one-directional road from city $s_j$ to city $t_j$ ($0 \le s_j, t_j \le n - 1$, $s_j \ne t_j$, $(s_j, t_j) \ne (s_i, t_i)$ if $i \ne j$).

출력

Print one integer: the maximum number of distinct Hokusai artworks Bytika can see while traveling on the island.

예제 입력 1

2 1
1 2
0 1

예제 출력 1

1

예제 입력 2

5 5
1 1 1 1 1
0 1
1 2
2 3
3 0
3 4

예제 출력 2

3

예제 입력 3

4 4
1 1 1 1
0 1
1 2
2 0
2 3

예제 출력 3

4