Treasure 1 - MarisaOJ: Marisa Online Judge

Treasure 1

Time limit: 1000 ms
Memory limit: 256 MB
Marisa has recently found a treasure map that leads her to an underground cave system consisting of n rooms and m one-way tunnels. The cave is so dark that Marisa needs to use her power to light it up. If she lights up a room i, room j can receive the light if j can be reached from i and i can also be reached in j. The cost of lighting up room i is Ai power. What is the minimum amount of power needed to completely eliminate the darkness in the cave? ### Input - The first line contains 2 integers n,m. - The second line contains n integers Ai. - The next m lines, each line contains two integers u,v, there is a tunnel between u and v. ### Output - Print the minimum amount of power. ### Constraints - 1≤n,m≤105. - 1≤Ai≤109. - 1≤u,v≤n. ### Example Input: 33123122331 Output: 1