Java Solution using Dijkstra Algorithm
class Solution {\n    \n    private int dijkstra(int[][] roads,int n){\n        long mod=(int)1e9+7;\n\t\t//PriorityQueue is used for sorting by time\n        Q
class Solution {\n    \n    private int dijkstra(int[][] roads,int n){\n        long mod=(int)1e9+7;\n\t\t//PriorityQueue is used for sorting by time\n        Queue<long[]> pq = new PriorityQueue<>((l, r) -> Long.compare(l[1], r[1]));\n        //Number of ways to reach a vertex from 0 in minimum time\n\t\tlong[] ways=new long[n];\n\t\t//Distance array to store the minimum time taken to reach a vertex\n        long[] dist=new long[n];\n\t\t//Filling dist array with infinite distance.\n        Arrays.fill(dist,(long)1e18);\n        dist[0]=0;\n\t\t//Number of ways to reach 0 is 1.\n        ways[0]=1;\n\t\t//We have to form graph roads array.\n        ArrayList<long[]>[] graph=new ArrayList[n];\n        for(int i=0;i<graph.length;i++) graph[i]=new ArrayList<>();\n        for(int[] road:roads){\n            graph[road[0]].add(new long[]{road[1],road[2]});\n            graph[road[1]].add(new long[]{road[0],road[2]});\n        }\n        pq.add(new long[]{0,0});\n\t\t//Normal Dijkstra bfs is implemented.\n\t\twhile(pq.size()>0){\n            long[] ele=pq.remove();\n            long dis=ele[1];\n\t\t\t//Node value we are on(Parent Node).\n            long node=ele[0];\n            for(long[] e:graph[(int)node]){\n\t\t\t//Adjancent Node weight from parent.\n                long wt=e[1];\n\t\t\t//Adjacent Node to parent\n                long adjNode=e[0];\n\t\t\t\t//If the wt+dis (i.e time here) is less than already time taken then will update dist[(int)adjNode] and number of ways will be equal to ways[(int)node]\n                if(wt+dis<dist[(int)adjNode]){\n                    dist[(int)adjNode]=wt+dis;\n                    ways[(int)adjNode]=ways[(int)node];\n                    pq.add(new long[]{adjNode,dist[(int)adjNode]});\n                }\n\t\t\t\t//if wt+dis (i.e time here) is equal to already taken time then we will add it in ways array.\n                else if(wt+dis==dist[(int)adjNode]){\n                    ways[(int)adjNode]=(ways[(int)node]+ways[(int)adjNode])%mod;\n                }\n            }\n        }\n         return (int)ways[n-1];\n    }\n\n    public int countPaths(int n, int[][] roads) {\n        return dijkstra(roads,n);        \n    }\n}
['Java']