JAVA solution shows Memory Limit Exceeded
\nclass Pair implements Comparable<Pair>\n{\n    int len,ele;\n    Pair(int len,int ele)\n    {\n        this.len=len;\n        this.ele=ele;\n    }\n    public
```\nclass Pair implements Comparable<Pair>\n{\n    int len,ele;\n    Pair(int len,int ele)\n    {\n        this.len=len;\n        this.ele=ele;\n    }\n    public int compareTo(Pair p)\n    {\n        return this.len-p.len;\n    }\n}\nclass Solution {\n    public int countRestrictedPaths(int n, int[][] edges) {\n        int[][] graph=new int[n+1][n+1];\n        for(int i=0;i<edges.length;i++)\n        {\n            graph[edges[i][0]][edges[i][1]]=edges[i][2];\n            graph[edges[i][1]][edges[i][0]]=edges[i][2];\n        }\n        int[] dis= dijkistra(n, graph);\n        int[] dp=new int[n+1];\n        int counter=dfs(graph, 1, n, dis, dp);\n        return counter;\n    }\n    int[] dijkistra(int n, int[][] g)\n    {\n        PriorityQueue<Pair>graph=new PriorityQueue<>();\n        int[] dis=new int[n+1];\n        Arrays.fill(dis,Integer.MAX_VALUE);\n        dis[n]=0;\n        graph.offer(new Pair(0,n));\n        while(graph.isEmpty()==false)\n        {\n            Pair p=graph.poll();\n            int u=p.ele;\n            int d=p.len;\n            if(d!=dis[u])\n                continue;\n            for(int i=1;i<=n;i++)\n            {\n                if(g[u][i]!=0)\n                {\n                    int w=g[u][i];\n                    int v=i;\n                    if (dis[v] > dis[u] + w) \n                    {\n                        dis[v] = dis[u] + w;\n                        graph.offer(new Pair(dis[v], v));\n                    }\n                }\n            }\n        }\n        return dis;\n    }\n    int dfs(int[][] graph, int x, int n, int[] dis, int[] dp)\n    {\n        if(dp[x]!=0)\n            return dp[x];\n        if(x==n)\n        {\n            return 1;\n        }\n        int counter=0;\n        for(int i=1;i<=n;i++)\n        {\n            if(dis[x]>dis[i]&&graph[x][i]!=0)\n            {\n                counter=(counter+dfs(graph, i, n, dis, dp))%1000000007;\n            }\n        }\n        return dp[x]=counter;\n    }\n}\n```\n**When i am submitting the above code then it shows the memory limit exceeded error on one of the test case but when i am running the same test case as cutom input then it works fine.\nCan some help me why it is happen and how can i solve this problem??????**
[]