【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 ...
随机推荐
- AutoCAD .NET二次开发(二)
今天专门讲一个--CommandMethod.我们都在知道CAD操作要快,必须要熟悉掌握各种命令.在Lisp开发中,在函数后C:即可添加一个命令,非常方法,在.NET API也可以非常方便的设置命令, ...
- Android Tint着色与帧动画结合
需求 最近遇到一个需求: 要求根据后台接口给的色值 显示不同色值的帧动画(UI给了三张透明色的图) 正常的帧动画 是配置在xml里三张静态图片 然后加载一下就完事了现有的静态图片是透明的 还没有填充颜 ...
- UVa145 Gondwanaland Telecom
Time limit: 3.000 seconds 限时:3.000秒 Problem 问题 Gondwanaland Telecom makes charges for calls accordin ...
- ZK框架笔记1、ZK Ajax框架简介
简介 ZK是一个基于事件驱动和组件的框架,他为web应用提供了丰富的接口.zk包括一个基于Ajax的事件驱动引擎.一整套丰富的XML用户接口语言(XML User Interface Langu ...
- Lr_debug_message,Lr_output_message,Lr_error_message,Lrd_stmt,Lrd_fetch
今天在群里,问了 Lr_debug_message,Lr_output_message,Lr_error_message,Lrd_stmt,Lrd_fetch.下 面我整理了下Lr_debug_mes ...
- Win7各个版本之间的区别
Windows7包含6个版本,分别为Windows7 Starter(初级版).Windows7 Home Basic(家庭普通版).Windows7 Home Premium(家庭高级版).Wind ...
- Android中Context的总结及其用法
在android中我们经常遇到这样的情况,在创建一个对象的时候往往需要传递一个this参数,比如:语句 MyView mView = new MyView(this),要求传递一个this参数,这个t ...
- Entity Framework Code First使用者的福音 --- EF Power Tool使用记之一(转载)
好像蛮长时间没有新文章带给大家了.前几天出差再加上忙着公司里的活儿,几乎都没时间上博客园了.今天正好有些时间,为大家简单介绍EF产品组新发布的一个牛逼的小工具——EF Power Tool(翻译的话, ...
- 关于audio标签播放跨域的问题
遇到过的错误: DOMException: The play() request was interrupted by a new load request. DOMException: Failed ...
- Zip 压缩问题件,获取真实扩展名
].InputStream); foreach (var element in _ZIP.Entries) { using (System.IO.StreamReader _ddd = new Sys ...