For this Question: Given a weighted undirected graph.Task is to find the shortest path from source vertex (vertex number 1) to all other vertices from 2 to n.Given 2 integers N and M. N represents the number of vertices in the graph. M represents the number of edges between any 2 vertices.
Then M lines follow, each line has 2 space separated integers  a, b  where a and b represents an edge from vertex a to vertex b and the weight of that edge = (a+b)%1000.

Constraints 
1<=N<=100000
1<=M<=1000000Print the shortest distances from the source vertex (vertex number 1) to all other vertices from 2 to n in separate line. Print "-1" in case the vertex can't be reached form the source vertex.Sample Input
4 5
1 2 
1 4 
4 2 
4 3 
2 3 
Sample Output
3
8
5
, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main(String args[] ) throws Exception {
        int n,m;
        BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
        String line = br.readLine();
        StringTokenizer st = new StringTokenizer(line);
        n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());
        ArrayList<ArrayList<int[]>> graph = new ArrayList<>(n+1);
        for ( int i= 0; i <= n; i++){
            graph.add( new ArrayList<int[]>());
        }

        for ( int i = 0; i < m; i++){
            int u,v,w;
            line = br.readLine();
            if ( line == null)
                continue;
            st = new StringTokenizer(line);
            u = Integer.parseInt( st.nextToken());
            v = Integer.parseInt( st.nextToken());
            w=(u+v)%1000;

            graph.get(u).add( new int[]{v,w});
            graph.get(v).add( new int[]{u,w});
        }
        long[] dist = Dijkstra(graph,1);
        for( int i = 2; i <= n ; i++){
            if(dist[i]==9223372036854775807L){
                System.out.println("-1");
            }
            else
                System.out.println(dist[i]);
        }
    }

    private static long[] Dijkstra( ArrayList<ArrayList<int[]>> graph, int source){
        int n = graph.size();
        long[] dist = new long[n];
        boolean[] visited = new boolean[n];
        Arrays.fill(dist,Long.MAX_VALUE);
        PriorityQueue<long[]> queue = new PriorityQueue<>( (long[] i1,long[] i2)->{
            if( i1[1] < i2[1])
                return -1;
            return 1;
        });

        queue.add(new long[]{source,0});
        while ( !queue.isEmpty()){

            long[] cn = queue.remove();
            if( visited[(int)cn[0]] ){
                continue;
            }
            visited[(int)cn[0]] = true;
            dist[(int)cn[0]] = cn[1];

            for( int[] neighbour : graph.get((int)cn[0])){
                if ( !visited[neighbour[0]] ){
                    long newdistance = cn[1] + neighbour[1];
                    if ( newdistance  < dist[neighbour[0]]){
                        dist[neighbour[0]] = newdistance;
                        queue.add( new long[]{neighbour[0],newdistance});
                    }
                }
            }
        }
        return dist;
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?