Answer: Flipkart , Online Assessment Questions (17th August 2023 | SDE Intern) | Items S
Answer · Posted Aug 2023
Question 3 Solution #include <iostream> #include <vector> #include <queue> #include <limits> using namespace std; const int INF = numeric_limits<int>::max(); struct Edge { int to; int dist1; int dist2; }; void dijkstra(int start, int end, const vector<vector<Edge>>& graph, vector<vector<int>>& distances) { priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq; distances[start][0] = 0; // Using only state highway distances[start][1] = 0; // Using national highway pq.push(make_pair(0, make_pair(start, 0))); while (!pq.empty()) { int current_distance = pq.top().first; int current = pq.top().second.first; int ...
The full answer & interview discussion are available to premium members.
Log in Create a free account