POJ3159 Candies
#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的更多相关文章
- poj3159 Candies(差分约束,dij+heap)
poj3159 Candies 这题实质为裸的差分约束. 先看最短路模型:若d[v] >= d[u] + w, 则连边u->v,之后就变成了d[v] <= d[u] + w , 即d ...
- poj3159 Candies(差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Candies Time Limit: 1500MS Memory Limit ...
- POJ-3159.Candies.(差分约束 + Spfa)
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 40407 Accepted: 11367 Descri ...
- POJ3159:Candies(差分约束)
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 39666 Accepted: 11168 题目链接:h ...
- POJ3159 Candies —— 差分约束 spfa
题目链接:http://poj.org/problem?id=3159 Candies Time Limit: 1500MS Memory Limit: 131072K Total Submiss ...
- POJ-3159 Candies 最短路应用(差分约束)
题目链接:https://cn.vjudge.net/problem/POJ-3159 题意 给出一组不等式 求第一个变量和最后一个变量可能的最大差值 数据保证有解 思路 一个不等式a-b<=c ...
- poj3159 Candies SPFA
题目链接:http://poj.org/problem?id=3159 题目很容易理解 就是简单的SPFA算法应用 刚开始用STL里的队列超时了,自己写了个栈,果断过,看来有时候栈还是快啊.... 代 ...
- [poj3159]Candies(差分约束+链式前向星dijkstra模板)
题意:n个人,m个信息,每行的信息是3个数字,A,B,C,表示B比A多出来的糖果不超过C个,问你,n号人最多比1号人多几个糖果 解题关键:差分约束系统转化为最短路,B-A>=C,建有向边即可,与 ...
- 转自作者:phylips@bmy
差分约束系统 2008-11-28 20:53:25| 分类: 算法与acm|举报|字号 订阅 出处:http://duanple.blog.163.com/blog/static/7097 ...
随机推荐
- 使用kubebapps 管理helm 仓库已经应用使用Monocular专门提供helm 仓库查找
Monocular 从1.0 开始专注于helm 的UI展示,对于部署以及维护已经去掉了,官方也提供了相关的说明以及 推荐了几个可选的部署工具,从使用以及架构上来说kubeapps 就是Monocul ...
- Docker容器里的进程为什么要前台运行?相同的问题:docker运行apache为什么带FOREGROUND参数?docker运行nginx为什么带`daemon off`参数?
<第一本Docker书>里面,讲到Docker容器启动web服务时,都指定了前台运行的参数. 例如apache: ENTRYPOINT [ "/usr/sbin/apache2& ...
- css 兼容性问题,整理
css 兼容性问题,整理: css 兼容性问题 说明 <input type="number"> 在chrome下,是不能输入非数字的字符的:但是在火狐63.0.3(2 ...
- oauth2 java 代码示例
@RequestMapping("/oauth") @Controller public class OauthController { String clientId = &qu ...
- 在pypi上发布python包详细教程
使用Python编程中Python的包安装非常方便,一般都是可以pip来安装搞定:pip install <package name>,我们自己写的python也可以发布在pypi上,很简 ...
- workerman的使用实践--并与solaris通信
Workerman与solarisTCP通信测试 1. 笔记本win7,tcp_test.php 2. solaris,test.c 编译命令: gcc test.c –o test –lsoc ...
- 静态Map类型变量赋初始值
private static Map<String,String> sysTypeList = new HashMap<String, String>(); static { ...
- 解决 Sublime text3 中文显示乱码问题【亲测可用】
一.安装包管理器 使用Ctrl+`快捷键或者通过View->Show Console菜单打开命令行,粘贴如下代码 import urllib.request,os; pf = 'Packag ...
- Sql语句的优化摘要
1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...
- jQuery实现商品详情 详细参数页面切换
利用index实现: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...