| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 0 | 0 | 0 | 0.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 | 8 | N ≤ 20 |
| 2 | 12 | N ≤ 500 |
| 3 | 25 | N ≤ 5000 |
| 4 | 55 | No additional constraints |
4 2 10 5 8 1 2 3 1 4
83
All posssible graphs in the given example:
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 ?번