一直对dijkstra算法的写法存在盲区,参考自链接,自己编写
http://blog.csdn.net/aozil_yang/article/details/52841437
优先级队列用得很精髓,同时重载运算符函数后面需要加const,以前一直用的friend。。。
再次感谢大牛的博客,受教了
这个dijkstra加入模板,收益很大
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=10000+10;
const int inf=0x3f3f3f;
struct edge{
int f,to,w;
edge(int a=0,int b=0,int c=0):f(a),to(b),w(c){
}
};
struct node{
int d,f;
node(int a=0,int b=0):d(a),f(b){
}
bool operator < (const node& t) const{
return d>t.d;
}
};
int ans[maxn],k=0,visit[maxn],an[maxn];
map<int,vector<int> >g;
priority_queue<node> q;
vector<e