[C++] : Using dikstra  + Toposort + DP
\n#define ll long long int\nconst ll M = 1e9 + 7;\n#define MOD_ADD(a,b,m) ((a % m) + (b % m)) % m\nclass Solution {\npublic:\n    \n    static bool compare(pair
```\n#define ll long long int\nconst ll M = 1e9 + 7;\n#define MOD_ADD(a,b,m) ((a % m) + (b % m)) % m\nclass Solution {\npublic:\n    \n    static bool compare(pair<ll,ll> a, pair<ll,ll> b)\n    {\n        return a.second > b.second; // for  min heap\n    }\n    \n    vector<ll> dikstra(ll src, vector<vector<pair<ll,ll>>> &adj, ll n)\n    {\n        vector<ll> dis(n, INT_MAX);\n        vector<ll> vis(n, 0);\n        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, function<bool(pair<ll,ll>, pair<ll,ll>)>> Q(compare); \n        \n        Q.push({src, 0});\n        while(!Q.empty())\n        {\n            pair<ll,ll> now = Q.top(); Q.pop();\n            \n            int u = now.first;\n                \n            if(vis[u]) continue;\n            vis[u] = 1;\n            dis[u] = now.second;\n            \n            for(auto x : adj[u])\n            {\n                int v = x.first;\n                int w = x.second;\n                \n                if(dis[v] > dis[u] + w)\n                {\n                    dis[v] = dis[u] + w;\n                    Q.push({v, dis[v]});\n                }\n            }\n        }\n        \n        return dis;\n    }\n    \n    vector<int> toposort(vector<vector<int>> &adj, int n)\n    {\n        vector<int> ans;\n        int indegree[n + 1];\n        memset(&indegree, 0x00, sizeof(indegree));\n        \n        for(int u = 1; u < n; u++)\n        {\n            for(auto v : adj[u])\n                indegree[v]++;\n        }\n        \n        queue<int> q;\n        for(int i = 1; i < n; i++) if(!indegree[i]) q.push(i);\n        \n        while(!q.empty())\n        {\n            int u = q.front(); q.pop();\n            ans.push_back(u);\n            \n            for(auto v : adj[u])\n            {\n                indegree[v]--;\n                if(!indegree[v]) q.push(v);\n            }\n        }\n        \n        return ans;\n    }\n    \n    int countRestrictedPaths(int n, vector<vector<int>>& edges) \n    {\n        vector<vector<pair<ll,ll>>> adj(n + 1); // u - > (v, w)\n        \n        for(auto e : edges)\n        {\n            ll u = e[0];\n            ll v = e[1];\n            ll w = e[2];\n            adj[u].push_back({v,w});\n            adj[v].push_back({u, w});\n        }\n        \n        //dis[i] = distance from i to n;\n        vector<ll> dis = dikstra(n, adj, n + 1);\n        \n        vector<vector<int>> DAG(n + 1);\n        for(auto e : edges)\n        {\n            int u = e[0];\n            int v = e[1];\n            \n            if(dis[u] > dis[v]) DAG[u].push_back(v);\n            if(dis[v] > dis[u]) DAG[v].push_back(u);\n        }\n        \n        vector<int> topo = toposort(DAG, n + 1);\n        \n        int dp[n + 1]; memset(&dp, 0x00, sizeof(dp));\n        dp[n] = 1;\n        \n        for(int i = topo.size() - 1; i >= 0; i--)\n        {\n            int u = topo[i];\n            for(auto v : DAG[u])\n                dp[u] = MOD_ADD(dp[u], dp[v], M);\n        }\n        \n        \n        return dp[1];\n        \n        return 0;\n    }\n};\n```
['Dynamic Programming', 'Topological Sort']