【笔记】
用二项堆实现优先队列O((V+E)lgV),所有顶点都从源点可达的话,O(ElgV)。
const int maxn=11111;
const int maxm=1111111;
struct EdgeNode{
int to;
int w;
int next;
};
struct HeapNode{
int d,u;
bool operator<(const HeapNode& rhs) const{
return d>rhs.d;
}
};
struct Dijkstra{
EdgeNode edges[maxm];
int head[maxn];
int edge,n;
void init(int n){
this->n=n;
memset(head,-1,sizeof(head));
edge=0;
}
void addedges(int u,int v,int c){
edges[edge].w=c,edges[edge].to=v,edges[edge].next=head[u],head[u]=edge++;
}
bool done[maxn];
int dis[maxn];
int pre[maxn];
void dijkstra(int s){
priority_queue<HeapNode>que;
for (int i=0;i<n;i++) dis[i]=INF;
dis[s]=0;