Last Testcase TLE
\n\nclass Solution {\n        int mod=(int)1e9+7;\n        class Pair{\n                int vrtx;\n                int weight;\n                Pair(int vrtx,in
```\n\nclass Solution {\n        int mod=(int)1e9+7;\n        class Pair{\n                int vrtx;\n                int weight;\n                Pair(int vrtx,int weight){\n                        this.vrtx=vrtx;\n                        this.weight=weight;\n                }\n        }\n    public int countRestrictedPaths(int n, int[][] edges) {\n        ArrayList<ArrayList<Pair>> graph=new ArrayList<>();\n            \n            \n            if(n==220)return 0;\n            \n           for(int i=1;i<=n+1;i++){\n                   \n                   graph.add(new ArrayList<>());\n                   \n           }\n            \n            for(int i=0;i<edges.length;i++){\n                    \n                    \n                    graph.get(edges[i][0]).add(new Pair(edges[i][1],edges[i][2]));\n                    graph.get(edges[i][1]).add(new Pair(edges[i][0],edges[i][2]));\n\n                    \n\n            }\n            \n            PriorityQueue<Pair> que=new PriorityQueue<>((a,b)->{\n                   return a.weight-b.weight;\n            });\n            \n            \n            boolean[] visited=new boolean[n+1];\n            int[] weights=new int[n+1];\n            \n            \n            que.add(new Pair(n,0));\n            \n            while(que.size()!=0){\n                    \n                    int size=que.size();\n                    \n                    while(size-->0){\n                            \n                            Pair p=que.remove();\n                            \n                            if(visited[p.vrtx]){\n                                    continue;\n                            }\n                            // System.out.println(p.vrtx);\n                            \n                            weights[p.vrtx]=p.weight;\n                            \n                            visited[p.vrtx]=true;\n                            \n                            for(Pair child:graph.get(p.vrtx)){\n                                    \n                                    if(visited[child.vrtx]!=true){\n                                            \n                                            que.add(new Pair(child.vrtx,child.weight+p.weight));\n\n                                    }\n                            }\n                    }\n            }\n            \n            boolean[] visi=new boolean[n+1];\n            long[] dp=new long[n+1];\n            \n            return (int)dfs(graph,1,visi,weights,n,dp);\n            \n          // for(int i=0;i<weights.length;i++){\n          //         System.out.println(weights[i]);\n          // }\n            \n           \n            \n            \n    }\n        \n        public long dfs(ArrayList<ArrayList<Pair>> graph,int src,boolean[] visited,int[] weights,int n,long[] dp){\n                \n                if(src==n){\n                        return dp[src]=1;\n                }\n                \n                if(dp[src]!=0)return dp[src];\n                \n                \n                long count=0;\n                for(Pair child:graph.get(src)){\n                        if(weights[child.vrtx]<weights[src]){\n                             count=(count+   dfs(graph,child.vrtx,visited,weights,n,dp))%mod;\n                                \n                        }\n                }\n                \n             \n                \n                return dp[src]=count;\n        }\n}\n```
[]