Dijkstra+heap

//Dijkstra+heap版本 #include #include using namespace std; #define maxm 20005 #define maxn 105 #define inf 0x3f3f3f3f struct edges { int u, c, next; }e[maxm]; struct node { int u, c; node (int u, int c) : u(u), c(c) {} friend bool operator < (node a,node b){ return a.c>b.c; } }; int dist[maxn], p[maxn]; bool used[maxn]; int N, M, idx; priority_queue q; void init() { idx = 0; memset(p, 0xff, sizeof(p)); } void addedge(int u, int v, int c) { e[idx].u = v; e[idx].c = c; e[idx].next = p[u]; p[u] = idx++; } void dijkstra(int s, int d) { int t, u, w; node tmp(s, 0); while(!q.empty()) q.pop(); for(int i=0; i

你可能感兴趣的:(Dijkstra+heap)