Logo
(追記) (追記ここまで)

19036번 - Hokusai Artworks 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB83375.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

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2018 > Day 9: Japanese+ Selection H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /