#K6106. Disconnecting Graph by Removing Minimum Cost Node

    ID: 31225 Type: Default 1000ms 256MiB

Disconnecting Graph by Removing Minimum Cost Node

Disconnecting Graph by Removing Minimum Cost Node

You are given an undirected graph with n nodes and m edges. Each node i has an associated cost a_i. The task is to remove a subset of nodes such that in the remaining graph no two nodes are connected by an edge. According to the strategy, for each connected component of the graph, you remove the node with the minimum cost. However, instead of summing up the costs from every component, the final answer is defined as the minimum value among all these removed costs.

Formally, let the connected components of the graph be \(C_1, C_2, \dots, C_k\). For each component \(C_j\), let \(m_j = \min_{i \in C_j} a_i\). The answer is \(\min_{1 \le j \le k} m_j\).

Note that if the graph has no edges, every node is considered as an isolated component. In that case, the answer will be the minimum cost among all nodes.

inputFormat

The input is given in the following format:

 n m
 a1 a2 ... an
 u1 v1
 u2 v2
 ...
 um vm

Here:

  • n is the number of nodes.
  • m is the number of edges.
  • ai is the cost of node \(i\).
  • Each edge is represented by two integers \(u\) and \(v\), indicating an undirected edge connecting nodes \(u\) and \(v\).

outputFormat

Output a single integer which is the minimum cost computed as follows: for every connected component, take the minimum cost among its nodes and then output the smallest among these values.

## sample
5 4
5 1 3 4 2
1 2
2 3
3 4
4 5
1