模板

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<queue>
using namespace std;
#define inf 2147483647
typedef long long ll;
const ll mod=1e9+;
const int maxn=+;
ll dis[maxn];
struct edg{
int to;
int w;
};
vector<edg > sm[maxn];
typedef pair<int ,int > P;//最短距离,标点
void dij(int v){
fill(dis,dis+maxn,-);
priority_queue<P,vector<P>,greater<P> > que;
que.push(P(,v));
P tem;
dis[v]=;
while(!que.empty()){
tem=que.top();
que.pop();
int i=tem.second;
if(tem.first>dis[i])
continue;
for(int j=;j<sm[i].size();j++){
edg e=sm[i][j];
if(dis[e.to]==-||dis[e.to]>dis[i]+e.w){
dis[e.to]=dis[i]+e.w;
que.push(P(dis[e.to],e.to));
}
}
}
}
int main(){
int n,m,s,t;
int u,v;
ll w;
ll ans=;
edg tem;
cin>>n>>m>>s>>t;
for(int i=;i<m;i++){
cin>>u>>v>>w;
w=log(w)/log();
tem.to=v;
tem.w=w;
sm[u].push_back(tem);
}
dij(s);
if(dis[t]==-){
cout<<"-1"<<endl;
}
else{
//cout<<dis[t]<<endl;
ll tem=;
while(dis[t]!=){
if(dis[t]%==){
ans=(ans*tem)%mod;
}
dis[t]/=;
tem=(tem*tem)%mod;
}
cout<<ans<<endl;
}
return ;
}

Dijkstra的优先队列的更多相关文章

  1. Dijkstra算法优先队列实现与Bellman_Ford队列实现的理解

    /* Dijkstra算法用优先队列来实现,实现了每一条边最多遍历一次. 要知道,我们从队列头部找到的都是到 已经"建好树"的最短距离以及该节点编号, 并由该节点去更新 树根 到其 ...

  2. dijkstra 的优先队列优化

    既然要学习算法,就要学习到它的精髓,才能够使用起来得心应手. 我还是远远不够啊. 早就知道,dijkstra 算法可以用优先队列优化,我却一直不知道该怎样优化.当时,我的思路是这样的:假设有n个顶点, ...

  3. 小木乃伊到我家 dijkstra + 链表 + 优先队列

    https://ac.nowcoder.com/acm/contest/96/E?&headNav=www&headNav=acm 题目描述   AA的欧尼酱qwb是个考古学家,有一天 ...

  4. dijkstra算法优先队列

    d[i] 是起点到 I 节点的最短距离 void Dijkstra(int s) { priority_queue<P, vector<P>, greater<P> &g ...

  5. 隐式Dijkstra:在状态集合中用优先队列求前k小

    这种技巧是挺久以前接触的了,最近又突然遇到几道新题,于是总结了一下体会. 这种算法适用的前提是,标题所述的"状态集合"大到不可枚举(否则枚举就行了qaq) ...

  6. poj 1511-- Invitation Cards (dijkstra+优先队列)

    刚开始想复杂了,一直做不出来,,,其实就是两遍dijkstra+优先队列(其实就是板子题,只要能有个好的板子,剩下的都不是事),做出来感觉好简单...... 题意:有n个车站和n个志愿者,早上每个志愿 ...

  7. POJ 2387 Til the Cows Come Home (最短路 dijkstra)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...

  8. ZOJ 3946 Highway Project(Dijkstra)

    Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar ...

  9. POJ 3037 Skiing(Dijkstra)

    Skiing Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4668   Accepted: 1242   Special ...

随机推荐

  1. django ORM数据库操作

    5.使用Django的ORM详细步骤: 1. 自己动手创建数据库 create database 数据库名; 2. 在Django项目中设置连接数据库的相关配置(告诉Django连接哪一个数据库) # ...

  2. weblogic启动脚本01

    DATE=`date +%Y%m%d%H%M%S` user=`whoami` logDir=/app/logs/sguap_admin #启动日志存放路径sguap是例子系统简称# logDestd ...

  3. 前端每日实战:63# 视频演示如何用纯 CSS 创作一台烤面包机

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/OEBJRN 可交互视频 此视频是可 ...

  4. Spring入门-框架搭建

    步骤: 导包 四个核心包: 日志包:由于市场上已经有更好的日志包,所以spring不用自己的,而是用apache的日志. 搞对象 由于spring是用来装对象的容器,所以得搞个对象让它装 书写配置文件 ...

  5. pandas模块之读取文件

    首先我们来看一个文件 1 男 北京 刘一 我笑 #跳过此行,序号1 2 女 上海 刘珊 你笑 3 男 杭州 刘五 他笑 #跳过此行,序号四 4 女 重庆 刘六 不笑了 下面来分析内容,并使用参数 1 ...

  6. docker-compose运行ES, Kibana和Cerebro

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11764003.html docker-compose.yaml version: '2.2' serv ...

  7. kali网络源配置

    使用vim对sources.list文件进行修改: $   vim /etc/apt/sources.list 随便挑选一个源添加到该文件中 ----------------------------- ...

  8. HAProxy基于Centos6.5安装及配置

    一.使用2.6内核Linux,配置sysctl参数 vi /etc/sysctl.conf #haproxy confignet.ipv4.tcp_tw_reuse = 1net.ipv4.ip_lo ...

  9. dotnet 跨平台编译发布

    dotnet publish 命令,bash脚本如下(Windows安装git即可建议sh关联) publish.sh #!/usr/bin/env bash # one line command: ...

  10. 09-排序2 Insert or Merge(25 分)

    According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...