#P10166. [DTCPC 2024] 环
[DTCPC 2024] 环
Background
Cycle.
Problem Description
Given a directed graph with no multiple edges and no self-loops, and a sequence , each time you may add a directed edge at a cost of . Find the minimum total cost to make it possible to find distinct vertices such that for all , there is an edge .
Input Format
The first line contains two integers (, ), denoting the number of vertices and edges in the graph.
The second line contains integers, denoting the sequence ().
The next lines each contain two integers (), meaning there is a directed edge .
Output Format
Output one integer in a single line, denoting the minimum cost.
5 5
1 2 3 4 5
1 2
2 3
3 4
1 5
5 4
3
Hint
Translated by ChatGPT 5