Inviting person $i$ costs $C_i$. People in the same friendship group all join once any one of them is invited. Given the friendship relations, print the minimum total cost to bring everyone into the guild if it is at most the budget $K$; otherwise print fail.
Input
First line $N$, $M$, $K$; second line $N$ costs $C_i$; then $M$ lines each with two acquaintances $a$, $b$ ($1 \le N, M \le 10^5$, $a \ne b$).
Output
Print the minimum total cost, or fail if it exceeds $K$.
Example 1
Input
5 3 10 5 8 2 7 4 1 2 2 3 4 5
Output
6
Example 2
Input
6 3 8 6 7 5 4 9 10 1 2 2 3 4 5
Output
fail
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.