不多说了。就是裸的模版题。

贴代码:

<span style="font-family:KaiTi_GB2312;font-size:18px;">#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 30500
#define M 200000
#define inf 0x3f3f3f3f
using namespace std;
struct KSD
{
int v,len,next;
}e[M];
int head[N],cnt;
void add(int u,int v,int len)
{
cnt++;
e[cnt].v=v;
e[cnt].len=len;
e[cnt].next=head[u];
head[u]=cnt;
}
struct Lux
{
int f,v;
bool operator < (const Lux &a)const
{return f>a.f;}
Lux(){}
Lux(int _f,int _v):f(_f),v(_v){}
};
int dist[N];
bool in[N];
int pqspfa(int s,int t)
{
priority_queue<Lux>pq;
int i,u,v;
memset(dist,0x3f,sizeof(dist));
dist[s]=0;
in[s]=1;
pq.push(Lux(0,s));
while(!pq.empty())
{
Lux U=pq.top();pq.pop();
u=U.v;
in[u]=0;
for(i=head[u];i;i=e[i].next)
{
v=e[i].v;
if(dist[v]>dist[u]+e[i].len)
{
dist[v]=dist[u]+e[i].len;
if(!in[v])
{
in[v]=1;
pq.push(Lux(dist[v],v));
}
}
}
}
return dist[t];
}
int n,m;
int main()
{
// freopen("test.in","r",stdin);
int i,j,k;
int a,b,c;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
printf("%d\n",pqspfa(1,n));
return 0;
}
</span>

【POJ3159】Candies 裸的pqspfa模版题的更多相关文章

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

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

  2. lct 模版题 bzoj 2002 2049

    很早就有人给我推荐的模版题,然后我最近才刷的(' '    ) 昨天的tree 不知道比他们高到哪里去了,我和他谈笑风生啊! bzoj 2002 弹飞绵羊 重点:这道题的cut和link 由于这道题链 ...

  3. HDU 2222 Keywords Search(AC自动机模版题)

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  4. PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)

    1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...

  5. POJ 2533 Longest Ordered Subsequence(LIS模版题)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Acc ...

  6. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  7. poj 2299 Ultra-QuickSort 逆序对模版题

    用树状数组求逆序数 唯一的坑点就是sum要用long long存 直接贴代码了 以后忘了还能直接看 2333…… PS:和hdu3743代码是一样的,因为两个都是逆序对模版题…… #include&l ...

  8. E - Just a Hook HDU - 1698 线段树区间修改区间和模版题

    题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...

  9. hdu 1286 找新朋友 欧拉函数模版题

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Des ...

随机推荐

  1. sql: oracle, for update和for update nowait的区别

    1. oracle for update和for update nowait的区别 http://www.cnblogs.com/quanweiru/archive/2012/11/09/276222 ...

  2. Do not wait until the conditions are perfect to begin. Beginning makes the conditions perfect(转)

    名言金句总是不嫌多,美国<公司>杂志(Inc.)列出让你在 2015 年受用无穷的十大金句,每天选一则当作一天的心灵指导,不只学习前人的精神和智慧,也能转化成工作和生活的动力!Cheers ...

  3. Windows Azure 安全最佳实践 - 第 5 部分:基于Claim 的标识,单点登录

    基于Claim的身份标识是处理网站与 Web 服务的身份认证和访问一种简单而强大的方式,无论您是在本地工作还是面向云工作.您可以通过减少自定义实施和使用基于Claim的单一简化标识模型,创建更安全的应 ...

  4. Boost::asio io_service 实现分析

    io_service的作用 io_servie 实现了一个任务队列,这里的任务就是void(void)的函数.Io_servie最常用的两个接口是post和run,post向任务队列中投递任务,run ...

  5. boa-0.94.13:Hello CGI

    CGI是什么 CGI全称是CommonGateway Interface,简称CGI,中文名叫做通用网关接口. CGI程序就是符合CGI接口规范的程序,相对于WebServer来说也叫外部程序. CG ...

  6. 用asio的定时器实现带超时的connect,备忘

    // test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <boost/asio.hpp> #inclu ...

  7. Struts2通过自己定义拦截器实现登录之后跳转到原页面

    这个功能对用户体验来说是非常重要的.实现起来事实上非常easy. 拦截器的代码例如以下: package go.derek.advice; import go.derek.entity.User; i ...

  8. C++ overloading contructor

     // overloading class constructors #include <iostream> using namespace std; class Rectangle ...

  9. 与众不同 windows phone (5) - Chooser(选择器)

    原文:与众不同 windows phone (5) - Chooser(选择器) [索引页][源码下载] 与众不同 windows phone (5) - Chooser(选择器) 作者:webabc ...

  10. 推荐一款功能强大的js 在线编辑器

    http://jszi.cn/public/oherub/11/edit