Dijikstra and BFS C++
\n\n\nclass Solution {\npublic:\n    int countRestrictedPaths(int n, vector<vector<int>>& edges) {\n        \n        // construct the graph map\n        vector
\n\n```\nclass Solution {\npublic:\n    int countRestrictedPaths(int n, vector<vector<int>>& edges) {\n        \n        // construct the graph map\n        vector<unordered_map<int, int>> graph(n);\n        for(auto e : edges) {\n            int x = e[0]-1;\n            int y = e[1]-1;\n            int d = e[2];\n            graph[x][y] = graph[y][x] = d; \n        }\n\n        //Dijkstra Algorithm\n        vector<int> distance(n, INT_MAX);\n        distance[n-1] = 0;\n        \n        auto cmp = [&](const int& lhs, const int& rhs) {return distance[lhs] > distance[rhs]; };\n        priority_queue<int, vector<int>, decltype(cmp)> nodes(cmp);\n        \n        nodes.push(n-1);\n        \n        while( !nodes.empty() ) {\n            int x = nodes.top(); nodes.pop();\n            for(const auto & [ y, d ] : graph[x]) {  \n                if ( distance[y] > d + distance[x] ) {\n                    distance[y] = d + distance[x];\n                    // if the node\'s distance is updated, \n                    // it\'s neighbor  must be recaluated \n                    nodes.push(y); \n                }\n            }\n        }\n\n        //Dynamic Programming for restric paths\n        vector<bool> visited(n, false);\n        vector<long> restriced_path(n, 0);\n        \n\t\t//start from the `end` node\n        nodes.push(n-1);\n        restriced_path[n-1] = 1;\n        visited[n-1] = true; \n        \n        while( !nodes.empty() ) {\n            int x = nodes.top(); nodes.pop();\n            for(const auto & [ y, d ] : graph[x]) { \n                if ( distance[y] > distance[x]) {\n                    restriced_path[y] += restriced_path[x];\n                    restriced_path[y] %= 1000000007;\n                }\n                if (!visited[y]) { // if y is not visited!\n                    nodes.push(y);\n                    visited[y] = true;\n                }\n            }\n        }\n        return restriced_path[0];\n    }\n};\n```
[]