【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=2015
这种水题真没啥好说的。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=55005, Q=N*10, oo=~0u>>2;
int q[Q], front, tail, d[N], vis[N], ihead[N], cnt, n, x, m;
struct ED { int to, w, next; }e[Q];
void add(int u, int v, int w) {
e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; e[cnt].w=w;
e[++cnt].next=ihead[v]; ihead[v]=cnt; e[cnt].to=u; e[cnt].w=w;
}
void spfa() {
q[tail++]=1;
for1(i, 2, n) d[i]=oo;
vis[1]=1;
while(front!=tail) {
int v, u=q[front++]; if(front==Q) front=0; vis[u]=0;
for(int i=ihead[u]; i; i=e[i].next) if(d[v=e[i].to]>d[u]+e[i].w) {
d[v]=d[u]+e[i].w;
if(!vis[v]) {
vis[v]=1;
q[tail++]=v; if(tail==Q) tail=0;
}
}
}
} int main() {
read(n); read(m); read(x);
for1(i, 1, m) {
int u=getint(), v=getint(), w=getint();
add(u, v, w);
}
spfa();
for1(i, 1, x) {
int u=getint(), v=getint();
printf("%d\n", d[u]+d[v]);
}
return 0;
}
【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)的更多相关文章
- 【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=2014 这应该是显然的贪心吧,先排序,然后按花费取 #include <cstdio> # ...
- 【BZOJ】1631: [Usaco2007 Feb]Cow Party(dijkstra)
http://www.lydsy.com/JudgeOnline/problem.php?id=1631 看到m<=100000果断用dij(可是好像dij比spfa还慢了在这里?)//upd: ...
- 【BZOJ】1632: [Usaco2007 Feb]Lilypad Pond(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1632 我简直是个sb... ... bfs都不会写.. 算方案还用2个bfs! 都不会整合到一个! ...
- 【BZOJ】2021: [Usaco2010 Jan]Cheese Towers(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=2021 噗,自己太弱想不到. 原来是2次背包. 由于只要有一个大于k的高度的,而且这个必须放在最顶,那 ...
- 【BZOJ】2100: [Usaco2010 Dec]Apple Delivery(spfa+优化)
http://www.lydsy.com/JudgeOnline/problem.php?id=2100 这题我要吐血啊 我交了不下10次tle.. 噗 果然是写挫了. 一开始没加spfa优化果断t ...
- 【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #i ...
- 【BZOJ】3538: [Usaco2014 Open]Dueling GPS(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=3538 题意不要理解错QAQ,是说当前边(u,v)且u到n的最短距离中包含这条边,那么这条边就不警告. ...
- 【BZOJ】2019: [Usaco2009 Nov]找工作(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=2019 spfa裸题.....将飞机场的费用变成负,然后spfa找正环就行了 #include < ...
- BZOJ 2015: [Usaco2010 Feb]Chocolate Giving( 最短路 )
裸最短路.. ------------------------------------------------------------------------------------ #include ...
随机推荐
- Office 如何复印身份证正反面到一张纸上
先把身份证任意一面放到打印机扫描的一侧(不要放到正中间) 正面扫描复印好之后,身份证翻面,还放在原来的位置 纸张拿出来之后,把已经有图案的放在上面,空白的留在下面,接着扫描 最后效果如下 ...
- MySQL数据库如何导入导出
1 点击任意一个数据库,然后点击导出,导出为SQL格式,其他一切保持默认(不要勾选"添加 DROP TABLE/DROP VIEW") 2 勾选"另存为文件"点 ...
- Core Data 更新某条指定记录数据
一:流程 同样需要先查询出指定记录 更新指定记录 二:代码: //更新操作 - (void)updateThePersonData { NSFetchRequest *fetchRequest = [ ...
- ES6 for...of循环
1.for of const arr = ['red', 'green', 'blue']; for(let v of arr) { console.log(v); // red green blue ...
- (八)Oracle学习笔记—— 触发器
1. 触发器简介 触发器在数据库里以独立的对象存储,类似于过程(procedure)和函数(function),都有声明,执行和异常处理过程的PL/SQL块.它与存储过程和函数不同的是,存储过程与函数 ...
- 浅析C#中 ConcurrentDictionary的实现
简单画了一张图 (灵魂画手 →_→) 如图 ConcurrentDictionary 其中有个tables 对象主要存储,而这个 tables 是一个 很多区块的 数组 ,每个区块 又是一个node的 ...
- 阻塞IO、非阻塞IO的区别
1.类与类之间的关系:依赖,实现,泛化(继承),关联,组合,聚合. 1)依赖(虚线):一个类是 另一个类的函数参数 或者 函数返回值. 2)实现(实线加小圆):对纯虚函数类(抽象类)的实现. 3)继承 ...
- 如何给app客户端进行埋点?
1.什么是数据埋点? 当一款app开发完成后,一定需要查看数据,来分析用户访问量,点击量,转化率等等指标.想要查看数据,就得先做好数据埋点 注:html和app数据埋点的方式不同 2.常用app数据分 ...
- 特征组合&特征交叉
https://segmentfault.com/a/1190000014799038 https://www.jianshu.com/p/fc96675b6f8e https://blog.csdn ...
- mysql创建账号对应的数据库方法
增加一个用户mydb密码为123450, 让他只可以在(localhost/%)%表示可以支持远程上登录,并可以对数据库mydata5_db进行查询.插入.修改.删除的操作. grant select ...