/* ** This is a C++ implementation of Edger Wybe Dijkstra's algorithm ** for finding Single Source Shortest Path of a directed or undirected ** weighted graph. It's run-time complexity is O((V+E)logV). */ #include <cstdio> #include <cstring> #include <vector> #include <queue> using namespace std; class Pair { public: int v,w; Pair(int v_,int w_) {v=v_,w=w_;} bool operator<(const Pair &p) const {return w>p.w;} }; #define MAX 100 #define INF 2147483647 vector<int> adjList[MAX+7]; int V,adjMatrix[MAX+7][MAX+7],dist[MAX+7]; int process(int u,int t) { int v,w; priority_queue<Pair> Q; Q.push(Pair(u,0)), dist[u]=0; while(!Q.empty()) { u=Q.top().v, w=Q.top().w, Q.pop(); if(u==t) return w; else if(w>dist[u]) continue; for(int i=0;i<(int)adjList[u].size();i++) { v=adjList[u][i]; if(dist[v]>dist[u]+adjMatrix[u][v]) dist[v]=dist[u]+adjMatrix[u][v], Q.push(Pair(v,dist[v])); } } return INF; } int main() { /* code */ return 0; }
SSSP_Dijkstra's
Subscribe to:
Posts (Atom)