#K54517. Maximum Magic Difference
Maximum Magic Difference
Maximum Magic Difference
In this problem, you are given a set of regions, each with an associated magic value. Additionally, there are roads connecting some pairs of these regions. Your task is to compute the maximum absolute difference in magic values between any two directly connected regions.
More formally, you are given (N) regions and (M) roads. For each road, connecting regions (u) and (v), you need to calculate (|\text{magic}_u - \text{magic}_v|). Among all the roads, output the maximum computed value.
The input is provided via standard input and the output should be printed to standard output.
inputFormat
The first line contains two integers (N) and (M), representing the number of regions and the number of roads respectively.
The second line contains (N) integers, where the (i)-th integer denotes the magic value of the (i)-th region.
Each of the following (M) lines contains two integers (u) and (v), indicating that there is a road connecting regions (u) and (v).
()
Note: Regions are 1-indexed.
outputFormat
Print a single integer representing the maximum absolute difference in magic values between any two directly connected regions.## sample
5 4
3 1 4 1 5
1 2
2 3
3 4
4 5
4