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 ...
随机推荐
- hermes kafka 转http rest api 的broker 工具
hermes 与nakadi 是类似的工具,但是设计模型有很大的差异,hermes 使用的是webhook的模式(push) nakadi 使用的是pull(event stream),各有自己解决的 ...
- 实例对象与 new 命令
引用:https://wangdoc.com/javascript/oop/new.html JavaScript 语言的对象体系,不是基于"类"的,而是基于构造函数(constr ...
- 从后端接口下载文件的2种方式:get方式、post方式
从后端接口下载文件的2种方式 一.get方式 直接使用: location.href='http://www.xxx.com/getFile?params1=xxx¶ms2=xxxx' ...
- vue-router 与 react-router 设计理念上的区别
vue-router 与 react-router 设计理念上的区别: 区别 vue-router react-router 改成history mode: 'history' 直接使用 react- ...
- maven 内置变量
${basedir} 项目根目录 ${project.build.directory} 构建目录,缺省为target ${project.build.outputDirectory} 构建过程输出目录 ...
- Android 单元测试实践
1. 在Android Studio创建工程 工程名称 AndroidUnitTest 2. 创建测试类CommonUtil 在类中加入sum和multiply方法 在CommonUtil类中右击 ...
- 修改postfix smtp端口,防止公网扫描浪费你的服务器流量
邮件服务器的默认发送邮件端口是25,一些ISP会封锁25端口防止垃圾邮件的发送,这样就导致不能使用Foxmail.outlook等邮件客户端发送邮件.修改默认smtp端口就可以解决这个问题.下面的方法 ...
- linux 添加多个网段
1.在系统中添加网络配置文件脚本 # cd /etc/sysconfig/network-scripts # cp ifcfg-eth0 ifcfg-eth0:0 2.修改新添加的网络配置脚本文件如下 ...
- windows服务命令 转载
OnCustomCommand executes when the Service Control Manager (SCM) passes a custom command to the servi ...
- 【Spring学习笔记-2.1】Spring的设值注入和构造注入
设值注入: 先通过无参数的构造函数创建一个Bean实例,然后调用对应的setter方法注入依赖关系: 配置文件: <?xml version="1.0" encoding=& ...