这是一个模板
用的是disjiaska算法
通过这道题我学得了快读得写法
inline void read()
{
int x = 0, k = 1;
c = getchar();
while(c <'0' || c>'9') {if(c == '-') k= -1;c = getchar();}
while(c>='0' && c<='9') {
x = (x<<3) + (x<<1) + (c^48);
c = getchar();
}
return x*k;
}
priority_queueq;//优先队列
在这里面用到了这个优先队列 这个比直接得queue好吧
还有就是 我这个方法用到了大根堆,
struct node{//大根堆
int w, now;//w长度,now是当前点
inline bool operator <(const node &x) const{//重载运算符把最小的元素放在堆顶了
return w>x.w;
}
};
这是用到的disjiska模板,也是很简易理解的
void disjiska()
{
for(int i=1; i<=n; i++)
{
dis[i] = INF;
}
dis[s] = 0;//初始化
q.push((node){0,s});
//vis[s] = 1;
while(!q.empty()){
node x = q.top();
q.pop();
int k = x.now;//拿出现在这个点
if(vis[k]) continue;//如果遍历过了就跳过
vis[k] = 1;
for(int i=head[k]; i; i=e[i].next)//开始寻找这个点的附近最短的路径
{
int v = e[i].v;
if(dis[v] > dis[k]+e[i].w)//递归dp取是否应该取这个数
{dis[v] = dis[k] + e[i].w;
q.push((node){dis[v], v});//把那个点放进序列
}
}
}
这道题花了我快一天的时间在那里找一个点的零分,其实就是题目的数据界限,我以为无穷大就可以,其实要精确到文章提到的具体数字。