Java readable version with summary from other solutions
\n        it was hard question to me\n        I tried to made it simpler from @kniffina solution         \n        \n        key 3 things I could not figure out
\n        it was hard question to me\n        I tried to made it simpler from @kniffina solution         \n        \n        key 3 things I could not figure out\n        after construct a graph\n        \n        1. BFS to find distance from N to 1 **(NOT 1 to N) **  \n        **because of #2 condtion**\n\t\t\n        2. DFS to count the number of nodes ---> **if distanceToN(u) > distanceToN(v)**\n           **and memiozation for performance in #3**\n        \n        3.  use array to store interim result (DP)\n                        \n    \n    \n\t\n\t```\nclass Solution {\n    \n    \n    \n    private int M=(int)1e9+7;\n    \n    public int countRestrictedPaths(int n, int[][] edges) {\n        \n        //construct \n        Map<Integer,Map<Integer,Integer>> map = new HashMap<>();        \n        for(int[] e:edges){\n            int u=e[0];\n            int v=e[1];\n            int w=e[2];\n            \n            map.putIfAbsent(u,new HashMap<>());\n            map.putIfAbsent(v,new HashMap<>());\n            map.get(u).put(v,w);\n            map.get(v).put(u,w);\n        }\n        \n        //find distance from N to 1 using BFS\n        int[] distance=new int[n+1];\n        PriorityQueue<int[]> pq = new PriorityQueue<>((a,b)->Integer.compare(a[1],b[1]));\n        pq.offer(new int[]{n,0});\n        \n        while(!pq.isEmpty()){\n            int[] vw=pq.poll();\n            int v=vw[0];\n            int w=vw[1];\n            \n            for(Map.Entry<Integer,Integer> et:map.get(v).entrySet()){                \n                int v2=et.getKey();\n                int w2=et.getValue();\n                \n                if(v2==n)\n                    continue;\n                \n                if(distance[v2]==0 || w+w2<distance[v2]){\n                    distance[v2]=w+w2;\n                    pq.offer(new int[]{v2,w+w2});\n                }\n            }                        \n            \n        }\n        \n        //dfs using dp array\n        int[] dp = new int[n+1];\n        Arrays.fill(dp,-1);\n        return dfs(1,n,dp,distance,map);        \n        \n    }\n    \n    private int dfs(int curr,int n,int[] dp,int[] distance,Map<Integer,Map<Integer,Integer>> map){\n        if(curr==n)\n            return 1;\n        \n        if(dp[curr]!=-1)\n            return dp[curr];\n        \n        int ans=0;\n        for(Map.Entry<Integer,Integer> et:map.get(curr).entrySet()){\n            int v=et.getKey();\n            if(distance[curr]>distance[v])\n                ans = (ans + dfs(v,n,dp,distance,map))%M;\n        }\n        \n            \n       return dp[curr]=ans;             \n    }\n    \n    \n}\n```
[]