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

24556번 - Abridged Reading 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB68353054.545%

문제

Miss Othmar is a grade school teacher who uses a very interesting textbook in her science class. All of the chapters in the book have material that depends on at most one previous chapter's material, while several chapters are labeled "Culminating Concept" chapters that have no chapters depending on them –-- they basically represent the culmination of the stream of material in all the previous chapters that must be read before them. Chapters that are not Culminating Concept chapters are referred to as "prerequisite chapters."

Because of various delays caused by the pandemic, Miss Othmar is far behind where she wants to be in the class. It's too late to try to cover all of the Culminating Concept chapters in the book (and their required prerequisite chapters) so she has decided to cover just two more Culminating Concept chapters. To give the kids a break she has decided to pick the two Culminating Concept chapters which require the least amount of reading –-- this would include not only those chapters but their prerequisite chapters as well.

입력

Input starts with a line containing two integers $n$ $m$ where $n$ (2ドル \leq n \leq 1,000円$) indicates the number of chapters (numbered 1ドル$ to $n$) and $m$ (0ドル \leq m < n$) indicates the number of chapter dependencies. After this are $n$ positive values indicating the number of pages in each chapter. These values will be on one or more lines and the number of pages in any chapter is $ \leq 1,000円$. After this are $m$ lines each containing two integers $a$ $b$ $(1 \leq a < b \leq n)$ indicating that chapter $a$ must be read before chapter $b$. No chapter appears as the second integer in these lines more than once. There will be at least two Culminating Concept chapters.

출력

Output the minimum number of pages that need to be read in order to complete two Culminating Concept chapters.

제한

예제 입력 1

7 6
10 9 6 4 2 10 12
1 2
1 3
2 4
2 5
3 6
3 7

예제 출력 1

25

예제 입력 2

4 2
10 7 4 6
1 4
2 3

예제 출력 2

27

힌트

출처

ICPC > Regionals > North America > East Central North America Regional > 2021 East Central Regional Contest B번

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

출처

대학교 대회

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

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