Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void dijkstra(vector<vector<int>> graph, int src, int V)
- {
- queue<int>q;
- q.push(src);
- vector<int> dis(V, INT_MAX);
- dis[src]=0;
- while(!q.empty())
- {
- int u=q.front();
- q.pop();
- for(int j=0;j<V;j++)
- {
- if(graph[u][j]!=0&&dis[j]>dis[u]+graph[u][j])
- {
- dis[j]=dis[u]+graph[u][j];
- q.push(j);
- }
- }
- }
- for(auto x:dis)cout<<x<<" ";
- }
Add Comment
Please, Sign In to add comment