DP + Dijkstra + DFS  = SOLUTION
\n\n# Code\n\nclass Solution {\npublic:\n    int mod = 1e9+7;\n    // simple dijkstra to find shortest distance from node n \n    vector<int> dijkstra(vector<ve
\n\n# Code\n```\nclass Solution {\npublic:\n    int mod = 1e9+7;\n    // simple dijkstra to find shortest distance from node n \n    vector<int> dijkstra(vector<vector<pair<int,int>>>&adj, int n){\n\t    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int>>> pq;\n        vector<int> distTo(n+1,INT_MAX);\n        pq.push({0,n});\n        distTo[n] = 0;\n        while(!pq.empty()){\n            int weight = pq.top().first;\n            int node   = pq.top().second;\n            pq.pop();\n            for(auto it: adj[node]){\n                int adjNode = it.first;\n                int edgW  = it.second;\n                if(weight + edgW < distTo[adjNode]){\n                    distTo[adjNode]  =  weight +  edgW;\n                    pq.push( {distTo[adjNode],adjNode} );\n                }\n            }\n        }\n        return distTo;\n    }\n\n    // dfs to check which path satisfying the conditions \n    int dfs(vector<vector<pair<int,int>>>&adj, vector<int>& dp, vector<int>& dist, int src){\n        int sum =0;\n        if(src==1) return 1;\n        if(dp[src]!=-1) return dp[src];\n\n        for(auto adjNode:adj[src]){\n            int costFromIthNode  = dist[src];\n            int costFromNextNode = dist[adjNode.first];\n            if(costFromNextNode > costFromIthNode) // condition satisfied \n                sum = (sum% mod + dfs(adj,dp,dist,adjNode.first)%mod) % mod;\n            // dont be confused with the condition that in question it was written distanceToLastNode(zi) > distanceToLastNode(zi+1) \n            // but here is am doing opposite that\'s because i am traversing the graph the last \n        }\n        return dp[src] = sum% mod;\n\n    }\n \n    int countRestrictedPaths(int n, vector<vector<int>>& edges) {\n        vector<vector<pair<int,int>>>graph(n+1);\n        for(auto it:edges){\n            graph[it[0]].push_back({it[1],it[2]});\n            graph[it[1]].push_back({it[0],it[2]});\n        }\n        vector<int>dist = dijkstra(graph,n);\n        vector<int>dp(n+1,-1);\n        return dfs(graph,dp,dist,n);\n    }\n};\n```
['Dynamic Programming', 'Graph', 'C++']