Java Priority Queue
\npublic int countPaths(int n, int[][] roads) {\n        long [][]dp = new long[n][2];\n        ArrayList<long []> []graph = new ArrayList[n];\n        for(int 
```\npublic int countPaths(int n, int[][] roads) {\n        long [][]dp = new long[n][2];\n        ArrayList<long []> []graph = new ArrayList[n];\n        for(int i=0;i<n;i++){\n            graph[i] = new ArrayList();\n        }\n        for(int []road: roads){\n            int src = road[0];\n            int dest = road[1];\n            int dist = road[2];\n            graph[src].add(new long[]{dest, dist});\n            graph[dest].add(new long []{src, dist});\n        }\n        PriorityQueue<long []> pq = new PriorityQueue<long []>((a,b) -> Long.compare(a[2], b[2]));\n        for(int i=1;i<n;i++){\n            dp[i][0] = Long.MAX_VALUE;\n        }\n        dp[0][1] = 1;\n        for(int i=0;i<graph[0].size();i++){\n            long []tmp = graph[0].get(i);\n            pq.add(new long[]{0, tmp[0], tmp[1]});\n        }\n        long mod = 1000000007;\n        while(pq.size() > 0){\n            long []poll = pq.poll();\n            int src = (int)poll[0];\n            int dest = (int)poll[1];\n            long dist = poll[2];\n            if(dist <= dp[dest][0]){\n                dp[dest][1] = (dp[dest][1] + dp[src][1])%mod;\n            }\n            if(dist < dp[dest][0]){\n                dp[dest][0] = dist;\n                for(int i=0;i<graph[dest].size();i++){\n                    long []tmp = graph[dest].get(i);\n                    pq.add(new long[]{dest, tmp[0], tmp[1] + dp[dest][0]});\n                }\n            }\n        }\n        return (int)(dp[n-1][1] % mod);\n    }\n```
[]