#C8674. Minimum Vertex Cost

    ID: 52682 Type: Default 1000ms 256MiB

Minimum Vertex Cost

Minimum Vertex Cost

You are given an undirected graph with n vertices and m edges. Each vertex is associated with a cost. Your task is to remove some (or none) of the edges such that the remaining graph is a connected component, and then report the minimum possible sum of vertex costs of that connected component. It turns out that the optimal strategy is to choose the vertex with the smallest cost. In other words, you just need to output the minimum vertex cost among all vertices.

The problem can be formulated as follows:

For a graph with vertices numbered from 1 to \(n\) with associated costs \(a_1, a_2, \dots, a_n\), and a list of \(m\) edges, find \[ \min_{1 \le i \le n} a_i. \]

Note: The given edges do not affect the answer, as the minimum possible sum after obtaining one connected component is simply the cost of the vertex with the minimum cost.

inputFormat

The input is given from stdin and consists of the following:

  • The first line contains two integers \(n\) and \(m\), where \(n\) is the number of vertices and \(m\) is the number of edges.
  • The second line contains \(n\) space-separated integers representing the cost of each vertex.
  • The following \(m\) lines each contain two integers \(u\) and \(v\) denoting an edge between vertex \(u\) and vertex \(v\). (These values are provided for completeness but do not affect the answer.)

outputFormat

Print a single integer on a new line to stdout: the minimum vertex cost.

## sample
5 4
10 20 30 40 50
1 2
2 3
3 4
4 5
10

</p>