Commented and explained solution
``` \npublic int countPaths(int n, int[][] roads) {\n //the approach here will be same as djskarta but we will require to count the number of \n        //ways w
``` \npublic int countPaths(int n, int[][] roads) {\n //the approach here will be same as djskarta but we will require to count the number of \n        //ways we reached to every node through short cost path\n        //Catch is, whenver you find a better way to reach a particular vertex update the number of ways \n        // we can reach this vertex same as number of ways we can reach parent vertex.\n        //If we arrive at a vetrex, with same time from parent, we will add the parent\'s number of ways \n        // to the current vertex\'s number of ways\n        //In the End the last veretx will have total number of ways from origin i.e 0\n        final int mod = 1_000_000_007;\n        int[][] adj = new int[n][n];\n        //adjacency list creation\n        for(int[] road : roads){\n            adj[road[0]][road[1]] = road[2];\n            adj[road[1]][road[0]] = road[2];\n        }\n        //creating and filling ways and cost array\n        //it can be also said to be type of tabulation (dp) problem because we have to memorize the ways we reach to node\n        long[] cost = new long[n], ways = new long[n];\n        Arrays.fill(cost,1,n, Long.MAX_VALUE);\n        ways[0]=1;\n\n        Queue<long[]> q = new PriorityQueue<>((a, b)->Long.compare(a[1], b[1]));\n        q.offer(new long[]{0,0});\n\n        while(!q.isEmpty()){\n            long[] e = q.poll();\n            int v = (int) e[0];\n            long t = e[1];\n            if(t <= cost[v]){\n                for(int i=0;i<n;i++){\n                    if(adj[v][i]!=0){\n                        //here if we get a cheaper path to operate then we go through every path that is to adj[v][i] node\n                        if(cost[v]+adj[v][i] < cost[i]){\n                            cost[i] = cost[v]+adj[v][i];\n\n                            q.offer(new long[]{i,cost[i]});\n                            ways[i] = ways[v];\n                            \n                        }else if(cost[v]+adj[v][i] == cost[i]){//if cost is same then we will update the ways with which we \n                            //reach to parent node +current node\n                            ways[i] = (ways[i]+ways[v]) % mod;\n                        }\n                    }\n                }\n            }\n        }\n        return (int) ways[n-1];\n    }\n\t
['Dynamic Programming', 'Java']