report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Treasure 1 - FlandreOJ: Flandre 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 $A_i$ 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 $A_i$. - 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 \le n,m \le 10^5$. - $1 \le A_i \le 10^9$. - $1 \le u,v \le n$. ### Example Input: ``` 3 3 1 2 3 1 2 2 3 3 1 ``` Output: ``` 1 ```
Strongly connect component
Reachability
Treasure 1
Treasure 2
Topic
Graph
Rating 1400
Solution (0) Solution