#C10015. Connected Components Value Range
Connected Components Value Range
Connected Components Value Range
You are given an undirected graph with n vertices and m edges. Each vertex i (where i ranges from 1 to n) is associated with an integer value. A connected component is a set of vertices such that there is a path between any two vertices in that set.
Your task is to determine, for each connected component, the minimum and maximum values among its vertices. In other words, if a connected component C contains vertex values \(V_C = \{v_1, v_2, \dots, v_k\}\), you need to compute:
[ \min(V_C) \quad \text{and} \quad \max(V_C) ]
Output the result as one pair per line (i.e. min max
) for each connected component. The order of the output pairs should be ascending based on the minimum value.
Note: The graph is undirected and vertices are numbered from 1 to n.
inputFormat
The first line contains two integers n and m, which represent the number of vertices and the number of edges, respectively.
The second line contains n integers, where the i-th integer represents the value associated with the i-th vertex.
The next m lines each contain two integers, representing an undirected edge between two vertices.
outputFormat
For each connected component, output a single line containing two integers: the minimum and maximum vertex values within that component. The connected components must be listed in ascending order based on their minimum values.
## sample5 3
1 2 3 4 5
1 2
2 3
4 5
1 3
4 5
</p>