浙江工业大学
int from,to;........................................................................................................................................17
elem_t len;........................................................................................................................................17
edge_t* next;....................................................................................................................................17
edge_t* end;.....................................................................................................................................17
};........................................................................................................................................................17
#define _cp(a,b) ((a)<(b))..................................................................................................................17
struct heap{........................................................................................................................................17
elem_t h[MAXN+1];........................................................................................................................17
int ind[MAXN+1],map[MAXN+1],n,p,c;.......................................................................................17
void init(){n=0;}...............................................................................................................................17
void ins(int i,elem_t e){...................................................................................................................17
for (p=++n;p>1&&_cp(e,h[p>>1]);h[map[ind[p]=ind[p>>1]]=p]=h[p>>1],p>>=1);....................17
h[map[ind[p]=i]=p]=e;.....................................................................................................................17
}........................................................................................................................................................17
int del(int i,elem_t& e){...................................................................................................................17
i=map[i];if (i<1||i>n) return 0;.........................................................................................................17
for (e=h[p=i];p>1;h[map[ind[p]=ind[p>>1]]=p]=h[p>>1],p>>=1);...............................................17
for (c=2;c<n&&_cp(h[c+=(c<n-
1&&_cp(h[c+1],h[c]))],h[n]);h[map[ind[p]=ind[c]]=p]=h[c],p=c,c<<=1);.....................................17
h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;....................................................................................17
}........................................................................................................................................................17
int delmin(int& i,elem_t& e){..........................................................................................................17
if (n<1) return 0;i=ind[1];.................................................................................................................17
for (e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-
1&&_cp(h[c+1],h[c]))],h[n]);h[map[ind[p]=ind[c]]=p]=h[c],p=c,c<<=1);.....................................17
h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;....................................................................................17
}........................................................................................................................................................17
};........................................................................................................................................................18
void dijkstra(int n,edge_t* list[],int s,elem_t* min,int* pre){..........................................................18
heap h;..............................................................................................................................................18
edge_t* t;elem_t e;...........................................................................................................................18
int v[MAXN],i;.................................................................................................................................18
for (h.init(),i=0;i<n;i++)...................................................................................................................18
min[i]=((i==s)?0:inf),v[i]=0,pre[i]=-1,h.ins(i,min[i]);....................................................................18
while (h.delmin(i,e)).........................................................................................................................18
for (v[i]=1,t=list[i];t->next != NULL ;t=t->next)............................................................................18
if (!v[t->to]&&min[i]+t->len<min[t->to]).......................................................................................18
pre[t->to]=i,h.del(t->to,e),min[t->to]=e=min[i]+t->len,h.ins(t->to,e);...........................................18
}.........................................................................................................................................................18
int main()...........................................................................................................................................18
{.........................................................................................................................................................18
int cases,platformnum, connum;......................................................................................................18
int i,j;.................................................................................................................................................18
Tzjut009 第 6 页 2021-8-5