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

30247번 - Travels 서브태스크다국어

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

문제

Martynas is a travel enthusiast and writes reviews on an Internet blog. Today he wants to evaluate trips offered by a travel agency called Rail Baitlandija.

In Baitlandija there are N cities, numbered from 1 to N. These cities are connected by one-way rails so that it is possible to get from city i to city j by train only when i < j.

However, not all possible train routes are offered by Rail Baitlandija agency. This means that there are M pairs of cities (ai, bi) (ai < bi) where it is not possible to buy train tickets from city ai to city bi.

Martynas defines a trip to be such a sequence of cities (a1, a2, ..., ak) (k > 1) that for each city pair (ai, ai+1) (1 ≤ i ≤ k − 1) Rail Baitlandija offers train tickets from ai to ai+1. Today he decided to try each such trip exactly once.

Visiting city i brings him mi amount of pleasure even if he has already visited this city during the previous trip. Therefore, each trip (a1, a2, ..., ak) brings him (ma1 + ma2 + ... + mak) of pleasure and the pleasure experienced on all those trips is summed.

Having done all of the trips, Martynas became so happy that he forgot how much pleasure he had experienced in total. When writing the review, it is important to include this number, so he needs your help to calculate it.

Calculate the total pleasure experienced by Martynas. Output the answer modulo 109 + 7.

입력

The first line of the input contains two intgers N and M. On the second line there are N integers m1, m2, . . . , mN. They represent the amount of pleasure Martynas experiences in the ith city.

Further, there are M lines. Each of them contains two integers ai and bi, which mean that Rail Baitlandija does not sell tickets from city ai to city bi.

출력

Output one non-negative integer – the total amount of pleasure experienced by Martynas modulo 109 + 7.

제한

  • 1 ≤ N, M ≤ 200 000
  • 0 ≤ mi ≤ 1 000 000 for all 1 ≤ i ≤ N

서브태스크

번호배점제한
18

N ≤ 20

212

N ≤ 500

325

N ≤ 5000

455

No additional constraints

예제 입력 1

4 2
10 5 8 1
2 3
1 4

예제 출력 1

83

All posssible graphs in the given example:

  • 1 → 2
  • 1 → 3
  • 2 → 4
  • 3 → 4
  • 1 → 2 → 4
  • 1 → 3 → 4

So the total amount of pleasure experienced is: 15 +たす 18 +たす 6 +たす 9 +たす 16 +たす 19 = 83

힌트

출처

Olympiad > Lithuanian Olympiad in Informatics > Lithuanian Olympiad in Informatics 2016/2017 > National Round (2) > 10-12 Classes ?번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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