Java program for the above approach
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static boolean sfpa ( int V , int src , int Edges [ ] [ ] , int M ) {