#include <iostream>
#include <queue>
#include <cstring>
#define maxn 30005
#define scanf(x) scanf("%d", &x)
using namespace std; struct CNode
{
int next; // index of the next vector from the same vertex
int k; // the end vertex of the vector
int w;
int d; // distence from k to the source point
}edges[*maxn]; bool operator < (const CNode &C1, const CNode &C2)
{
return C1.w > C2.w;
} priority_queue<CNode> pq;
int cnt, N, head[maxn];
bool bUsed[maxn]; void build(int u, int v, int w)
{
edges[cnt].k = v;
edges[cnt].w = w;
edges[cnt].d = w;
edges[cnt].next = head[u];
head[u] = cnt++;
} int main()
{
int M;
CNode p;
cnt = ;
memset(head, -, sizeof(head));
memset(bUsed, , sizeof(bUsed));
scanf(N), scanf(M);
while (M--){
int a, b, r;
scanf(a), scanf(b), scanf(r);
build(a, b, r);
}
edges[].k = ;
edges[].w = ;
edges[].d = ;
edges[].next = -;
pq.push(edges[]);
while (!pq.empty()) {
p = pq.top(); pq.pop();
if (bUsed[p.k])continue;
else bUsed[p.k] = ;
if (p.k == N)break;
for (int i = head[p.k]; i != -; i = edges[i].next) {
if (bUsed[edges[i].k])continue;
edges[i].d = p.d + edges[i].w;
pq.push(edges[i]);
}
}
printf("%d\n", p.d);
return ;
}

POJ3159 Candies的更多相关文章

  1. poj3159 Candies(差分约束,dij+heap)

    poj3159 Candies 这题实质为裸的差分约束. 先看最短路模型:若d[v] >= d[u] + w, 则连边u->v,之后就变成了d[v] <= d[u] + w , 即d ...

  2. poj3159 Candies(差分约束)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Candies Time Limit: 1500MS   Memory Limit ...

  3. POJ-3159.Candies.(差分约束 + Spfa)

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 40407   Accepted: 11367 Descri ...

  4. POJ3159:Candies(差分约束)

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 39666   Accepted: 11168 题目链接:h ...

  5. POJ3159 Candies —— 差分约束 spfa

    题目链接:http://poj.org/problem?id=3159 Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submiss ...

  6. POJ-3159 Candies 最短路应用(差分约束)

    题目链接:https://cn.vjudge.net/problem/POJ-3159 题意 给出一组不等式 求第一个变量和最后一个变量可能的最大差值 数据保证有解 思路 一个不等式a-b<=c ...

  7. poj3159 Candies SPFA

    题目链接:http://poj.org/problem?id=3159 题目很容易理解 就是简单的SPFA算法应用 刚开始用STL里的队列超时了,自己写了个栈,果断过,看来有时候栈还是快啊.... 代 ...

  8. [poj3159]Candies(差分约束+链式前向星dijkstra模板)

    题意:n个人,m个信息,每行的信息是3个数字,A,B,C,表示B比A多出来的糖果不超过C个,问你,n号人最多比1号人多几个糖果 解题关键:差分约束系统转化为最短路,B-A>=C,建有向边即可,与 ...

  9. 转自作者:phylips@bmy

    差分约束系统 2008-11-28 20:53:25|  分类: 算法与acm|举报|字号 订阅     出处:http://duanple.blog.163.com/blog/static/7097 ...

随机推荐

  1. openresty 集成 keycloak-oauth-oidc

    keycloak 是一个比较全,而且比较方便的sso 解决方案,同时为我们提供了灵活的扩展特性 备注: 测试使用docker-compose 运行,对于keycloak 使用pg 数据库做为后端存储 ...

  2. GCC related commands

    GCC   -l  option is to link the library. It can use for static and share link.  Link -l with library ...

  3. Big-endian/Little-endian, LSB/MSB

    Least significant byte (LSB) Most significant byte (MSB) Big-endian machines store the most-signific ...

  4. laya的那些坑

    游戏运行在chrome里面 听不见声音 游戏运行在chrome里面  听不见声音:其它浏览器可以听见声音开发者模式提示如下: The AudioContext was not allowed to s ...

  5. ML(4)——逻辑回归

    Logistic Regression虽然名字里带“回归”,但是它实际上是一种分类方法,“逻辑”是Logistic的音译,和真正的逻辑没有任何关系. 模型 线性模型 由于逻辑回归是一种分类方法,所以我 ...

  6. koa 学习资料

    koa 学习资料 学习资料 地址 koa 中文版 https://koa.bootcss.com/

  7. vue-cli 项目优化之3种方法对比:本地静态库资源(推荐)、cdn、DllPlugin

    vue-cli 项目优化之3种方法对比:本地静态库资源(推荐).cdn.DllPlugin 事项 本地静态库资源 cdn DllPlugin 依赖 依赖cdn网站资源(有种完善方法:如果cdn引入不成 ...

  8. js正则表达式只能是数字、字母或下划线

    //只能是数字.字母或下划线 function isValid(str) { var reg = /^\w+$/g; return reg.test(str); }

  9. Docker中使用nginx镜像

    1.到网易蜂巢查看nginx https://c.163yun.com/hub#/m/home/ 复制nginx镜像地址为:docker pull hub.c.163.com/library/ngin ...

  10. 时钟分频方法---verilog代码

    时钟分频方法---verilog代码 本文以SDI播出部分的工程为例,来说明一种时钟分频的写法.SD-SDI工程中播出时钟tx_usrclk为148.5MHz,但tx_video_a_y_in端的数据 ...