kuangbin_ShortPath K (POJ 3159)
很简单的模板题 放在K那么后的位置的原因大概是 光看题意并不是很容易想到是用最短路解吧
奈何kuangbin分在了最短路专题 一发水过
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#define INF 0x3F3F3F3F
using namespace std; const int MAXN = 3e4 + ;
const int MAXM = 15e4 + ; typedef pair<int, int> pii;
struct cmp{
bool operator () (const pii a, const pii b){
return a.first > b.first;
}
}; int size, head[MAXN], val[MAXM], point[MAXM], nxt[MAXM];
int n, m, dis[MAXN]; inline void add(int from, int to, int value)
{
val[size] = value;
point[size] = to;
nxt[size] = head[from];
head[from] = size++;
} void dij(int s, int t)
{
memset(dis, 0x3f, sizeof dis);
priority_queue<pii, vector<pii>, cmp> q;
q.push(make_pair(, s));
dis[s] = ;
while(!q.empty()){
pii u = q.top();
q.pop();
if(u.first > dis[u.second]) continue;
for(int i = head[u.second]; ~i; i = nxt[i]){
int j = point[i];
if(dis[j] > dis[u.second] + val[i]){
dis[j] = dis[u.second] + val[i];
q.push(make_pair(dis[j], j));
}
}
}
printf("%d\n", dis[t]);
}
int main()
{
memset(head, -, sizeof head);
scanf("%d%d", &n, &m);
while(m--){
int a, b, value;
scanf("%d%d%d", &a, &b, &value);
add(a, b, value);
}
dij(, n);
return ;
}
kuangbin_ShortPath K (POJ 3159)的更多相关文章
- POJ 3159 Candies (图论,差分约束系统,最短路)
POJ 3159 Candies (图论,差分约束系统,最短路) Description During the kindergarten days, flymouse was the monitor ...
- POJ 3159 Candies 解题报告(差分约束 Dijkstra+优先队列 SPFA+栈)
原题地址:http://poj.org/problem?id=3159 题意大概是班长发糖果,班里面有不良风气,A希望B的糖果不比自己多C个.班长要满足小朋友的需求,而且要让自己的糖果比snoopy的 ...
- POJ 3159 Candies(差分约束+spfa+链式前向星)
题目链接:http://poj.org/problem?id=3159 题目大意:给n个人派糖果,给出m组数据,每组数据包含A,B,C三个数,意思是A的糖果数比B少的个数不多于C,即B的糖果数 - A ...
- poj 3159(差分约束经典题)
题目链接:http://poj.org/problem?id=3159思路:题目意思很简单,都与给定的条件dist[b]-dist[a]<=c,求dist[n]-dist[1]的最大值,显然这是 ...
- POJ 3159 Candies(SPFA+栈)差分约束
题目链接:http://poj.org/problem?id=3159 题意:给出m给 x 与y的关系.当中y的糖数不能比x的多c个.即y-x <= c 最后求fly[n]最多能比so[1] ...
- POJ 3159 Candies(差分约束)
http://poj.org/problem?id=3159 题意:有向图,第一行n是点数,m是边数,每一行有三个数,前两个是有向边的起点与终点,最后一个是权值,求从1到n的最短路径. 思路:这个题让 ...
- POJ 3159 Candies 还是差分约束(栈的SPFA)
http://poj.org/problem?id=3159 题目大意: n个小朋友分糖果,你要满足他们的要求(a b x 意思为b不能超过a x个糖果)并且编号1和n的糖果差距要最大. 思路: 嗯, ...
- poj 3159 Candies(dijstra优化非vector写法)
题目链接:http://poj.org/problem?id=3159 题意:给n个人派糖果,给出m组数据,每组数据包含A,B,c 三个数,意思是A的糖果数比B少的个数不多于c,即B的糖果数 - A的 ...
- poj 3159 Candies 差分约束
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 22177 Accepted: 5936 Descrip ...
随机推荐
- 【转】Nginx+Tomcat+Memcached集群Session共享
cookie是怎样工作的? 例 如,我们创建了一个名字为login的Cookie来包含访问者的信息,创建Cookie时,服务器端的Header如下面所示,这里假设访问者的注册名 是“Michael J ...
- [转]change the linux startup logo
1. Make sure that you have the kernel sources installed. As annoying as this may seem, you will need ...
- matlab图形句柄属性总结
原文在于雪漫的bloghttp://blog.sina.com.cn/s/blog_4b9b714a0100cce2.html这两天在看句柄式图形方面的东西,以下是我在看书过程中整理的学习笔记,比较详 ...
- 在shell脚本中使用函数
转载请标明:http://www.cnblogs.com/winifred-tang94/ 对于在脚本中重复使用的功能模块,可以封装成为函数. shell脚本中函数的定义可以使用如下两种方式: a. ...
- python3控制路由器--使用requests重启极路由.py
代码写了相应的注释,以后再写成可以方便调用的模块. 用fiddler抓包可以看到很多HTTP头,经过尝试发现不是都必须的. 'Upgrade-Insecure-Requests':1,#必要项,值为1 ...
- poj2193
//Accepted 368K 532MS //线性dp //dp[i][j]表示前i位最后一个是j的排列数 //dp[i][j]=sum(dp[i-1][h]) h*2<=j #include ...
- FR #2题解
A. 考虑把(u,v)的询问离线挂在u上,然后dfs,每次从fath[x]到[x]相当于x子树dis区间加1,x子树以外区间-1,然后维护区间和区间平方和等. 常数略大. #include<io ...
- XAMPP Apache 配置多端口和多域名方法
我们在工作中经常遇到同时调试多个网站的情况,那么如何配置呢?就像平时访问网站一样,网站 a.com 与网站 b.com 截然不同.这都是常见现象,如果在局域网中要访问另外一台电脑上的多个网站,就需要使 ...
- select2美化下拉单
http://www.51xuediannao.com/js/jquery/select2.html http://www.51xuediannao.com/demo.php
- 7、SQL基础整理(子查询)
子查询 (用来进行两个或以上表之间的查询) 1.首先新建一个bumen表和一个haha表,填充数据 2.利用两表进行子查询: --部门人数大于5的部门中最大年龄的人的信息--- select MAX( ...