//前向星
struct node {
int nxt;
int val;
int lst;
node () {}
node (int next, int value) : nxt(next), val(value) {}
}; struct headnode {
int u;
int val;
headnode () {}
headnode (int uu, int value) : u(uu), val(value) {}
bool operator < (const headnode &a) const {
return val > a.val;
}
}; // 用于优先队列而已。val是比较的值。dist[i] int dist[maxn];
bool vis[maxn]; node edge[maxn];
int last[maxn] void Dij()
{
memset(dist, 0x3f, sizeof(dist));
memset(vis, , sizeof(vis));
priority_queue<headnode> pq;
pq.push(headnode(, ));
dist[] = ;
headnode now;
while (!pq.empty()) {
now = pq.top(); pq.pop();
if (vis[now.u]) continue;
vis[now.u] = true;
for (int i=last[now.u]; i!=-; i=edge[i].lst) {
if (dist[edge[i].nxt] > edge[i].val + dist[now.u]) {
dist[edge[i].nxt] = edge[i].val + dist[now.u];
pq.push(headnode(edge[i].nxt, dist[edge[i].nxt]));
}
}
}
}

Dij_heap__前向星。的更多相关文章

  1. 大规模图的存储(前向星、next数组)

    大规模图的储存 在信息学中,经常会遇到比较大规模图,使用指针固然是很好的方法,不过一有指针速度不如数组之说,二有指针不如数组稳定之说,三有,也是最重要的,指针不如数组来得方便,这也便是大多数Oier不 ...

  2. 链式前向星+SPFA

    今天听说vector不开o2是数组时间复杂度常数的1.5倍,瞬间吓傻.然后就问好的图表达方式,然后看到了链式前向星.于是就写了一段链式前向星+SPFA的,和普通的vector+SPFA的对拍了下,速度 ...

  3. 单元最短路径算法模板汇总(Dijkstra, BF,SPFA),附链式前向星模板

    一:dijkstra算法时间复杂度,用优先级队列优化的话,O((M+N)logN)求单源最短路径,要求所有边的权值非负.若图中出现权值为负的边,Dijkstra算法就会失效,求出的最短路径就可能是错的 ...

  4. hdu2647 逆拓扑,链式前向星。

    pid=2647">原文地址 题目分析 题意 老板发工资,可是要保证发的工资数满足每一个人的期望,比方A期望工资大于B,仅仅需比B多1元钱就可以.老板发的最低工资为888元.输出老板最 ...

  5. 图的存储结构:邻接矩阵(邻接表)&链式前向星

    [概念]疏松图&稠密图: 疏松图指,点连接的边不多的图,反之(点连接的边多)则为稠密图. Tips:邻接矩阵与邻接表相比,疏松图多用邻接表,稠密图多用邻接矩阵. 邻接矩阵: 开一个二维数组gr ...

  6. HDU 3726 Graph and Queries 平衡树+前向星+并查集+离线操作+逆向思维 数据结构大综合题

    Graph and Queries Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. 【模板】链式前向星+spfa

    洛谷传送门--分糖果 博客--链式前向星 团队中一道题,数据很大,只能用链式前向星存储,spfa求单源最短路. 可做模板. #include <cstdio> #include <q ...

  8. codeforces 893C Rumor 前向星+dfs

    893C Rumor 思路: 前向星+DFS 代码: #include <bits/stdc++.h> using namespace std; #define _for(i,a,b) f ...

  9. zzuli 2131 Can Win dinic+链式前向星(难点:抽象出网络模型+建边)

    2131: Can Win Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 431  Solved: 50 SubmitStatusWeb Board ...

随机推荐

  1. ActiveMQ 的连接和会话

    要了解 connection 和 session 的概念,可以先从 ConnectionState 和 SessionState 入手: // 省略部分代码 public class Connecti ...

  2. python heapq模块使用

    Python内置的heapq模块 Python3.4版本中heapq包含了几个有用的方法: heapq.heappush(heap,item):将item,推入heap >>> it ...

  3. Qt绘制文本二 弯曲排列和旋转效果 弧形路径 正弦函数路径

    void WgtText::paintEvent(QPaintEvent *event) { QPainter painter(this); QString m_string("abcdef ...

  4. POJ 2373 Dividing the Path(DP + 单调队列)

    POJ 2373 Dividing the Path 描述 农夫约翰的牛发现,在他的田里沿着山脊生长的三叶草是特别好的.为了给三叶草浇水,农夫约翰在山脊上安装了喷水器. 为了使安装更容易,每个喷头必须 ...

  5. 【基础】火狐和谷歌在Selenium3.0上的启动(二)

    参考地址:http://www.cnblogs.com/fnng/p/5932224.html https://github.com/mozilla/geckodriver [火狐浏览器] 火狐浏览器 ...

  6. tocat 域名绑定

    修改tomcat/conf/server.xml配置文件,新增部分如下 <Service name="Catalina1"> <Connector port=&q ...

  7. learning ddr mode register MR0

  8. JS 浮点型计算的精度问题 推荐的js 库 推荐的类库 Numeral.js 和 accounting.js

    推荐的类库 Numeral.js 和 accounting.js 文章来自 http://www.css88.com/archives/7324#more-7324

  9. 我眼中的Linux系统和红帽RHCE认证

    牛顿曾经说过“我不知道在别人看来,我是什么样的人:但在我自己看来,我不过就象是一个在海滨玩耍的小孩,为不时发现比寻常更为光滑的一块卵石或比寻常更为美丽的一片贝壳而沾沾自喜,而对于展现在我面前的浩瀚的真 ...

  10. bzoj1679

    题解: 前缀和 显然需要排序一下 注意爆int这件事 代码: #include<bits/stdc++.h> using namespace std; typedef long long ...