Hokusai Artworks
Time limit1sMemory limit512 MB
On a directed graph, each city has a museum open only on even days; find the maximum total weight of distinct museums visitable starting at city 0 on an even day.
- Level
Hard8 of 10
- Topics
- Graph, Dynamic programming, DFS, Greedy
- Solved
- No attempts yet
Problem
There are cities on some Japanese island and one-directional roads connecting those cities. Each city has a museum which is open on even days and is closed on odd days. The museum of the -th city holds Hokusai artworks.
Bytika arrived on the main city of the island (which 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 there are no chances to see new Hokusai artworks, she leaves the island by plane.
Find the maximum number of Hokusai artworks Bytika can see.
Input
The first line of input contains two integers and (, ): the number of cities and the number of roads. The second line contains integers , , , ; the -th of those integers is the number of Hokusai artworks in the museum of the -th city (). Each of the next lines contains two integers and denoting that there is a one-directional road from city to city (, , if ).
Output
Print one integer: the maximum number of distinct Hokusai artworks Bytika can see while traveling on the island.