Special paths
Practice
4.3 (7 votes)
Binary search
Algorithms
C++
Problem
83% Success 1265 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an undirected connected graph \(G\) with \(N\) nodes and \(M\) edges. Every node has a value \(A[i]\) assigned to it.

The value of a simple path between node \(u\) and \(v\) is as follows:

  • The maximum absolute difference between the values of adjacent nodes present in the simple path.

Find the minimum possible path value of any simple paths between start and end nodes.

Input format

  • The first line contains two space-separated integers \(N\) and \(M\) denoting the number of nodes and edges respectively.
  • Next \(M\) lines contain two space-separated integers denoting edges.
  • The next line contains \(N\) space-separated integers denoting node values.
  • The next line contains two space-separated integers denoting the start ends.

Output format

Print the minimum possible path value of any simple path between start and end nodes.

Constraints

\(1 \le N \le 10^5 \\ N - 1 \le M \le \text{min} (10^5 , N \times (N-1)/2) \\ 1 \le A[i] \le 10^6\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
5 votes
Tags:
Binary SearchTreesMathAlgorithms
Points:20
354 votes
Tags:
ReadyMapApprovedEasy
Points:50
4 votes
Tags:
AlgorithmsBinary Search