【BZOJ】3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)
http://www.lydsy.com/JudgeOnline/problem.php?id=3394
裸的floyd。。
#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 printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; 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=505;
int d[N][N], n, f, m, l[N]; int main() {
read(n); read(f); read(m);
CC(d, 0x3f);
rep(i, f) read(l[i]);
rep(i, m) {
int u=getint(), v=getint(), w=getint();
d[u][v]=d[v][u]=w;
}
for1(i, 1, n) d[i][i]=0;
for1(k, 1, n) for1(i, 1, n) for1(j, 1, n) d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
int ans, mn=~0u>>1;
for1(i, 1, n) {
int sum=0;
rep(j, f) if(d[i][l[j]]!=0x3f3f3f3f) sum+=d[i][l[j]];
if(sum<mn) {
mn=sum;
ans=i;
}
}
print(ans);
return 0;
}
Description


Input
第1行输入三个整数P,F C.之后F行每行输入一个整数表示一个贝茜喜欢的牧场.之后C行每行输入三个整数ai,bi,Ti,描述一条路.
Output
一个整数,满足题目要求的最佳牧场.如果有多个答案,输出编号最小的
Sample Input
11
13
10
12
8
1
2 4 3
7 11 3
10 11 1
4 13 3
9 10 3
2 3 2
3 5 4
5 9 2
6 7 6
5 6 1
1 2 4
4 5 3
11 12 3
6 10 1
7 8 7
Sample Output
HINT
Source
【BZOJ】3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)的更多相关文章
- BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 11 Solved: 9[Sub ...
- bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MB Submit: 665 Solved: 227[Sub ...
- [BZOJ 1576] [Usaco2009 Jan] 安全路经Travel 【树链剖分】
题目链接: BZOJ - 1576 题目分析 首先Orz Hzwer的题解. 先使用 dijikstra 求出最短路径树. 那么对于一条不在最短路径树上的边 (u -> v, w) 我们可以先沿 ...
- BZOJ.1576.[Usaco2009 Jan]安全路经Travel(树形DP 并查集)
题目链接 BZOJ 洛谷 先求最短路树.考虑每一条非树边(u,v,len),设w=LCA(u,v),这条边会对w->v上的点x(x!=w)有dis[u]+dis[v]-dis[x]+len的距离 ...
- bzoj 1576 [Usaco2009 Jan]安全路经Travel(树链剖分,线段树)
[题意] 给定一个无向图,找到1-i所有的次短路经,要求与最短路径的最后一条边不重叠. [思路] 首先用dijkstra算法构造以1为根的最短路树. 将一条无向边看作两条有向边,考察一条不在最短路树上 ...
- BZOJ 1574: [Usaco2009 Jan]地震损坏Damage
Description 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有牛棚间的路经都还能使用. FJ的农场有P(1 <= P <= 30,000)个牛棚,编号1.. ...
- bzoj:1575: [Usaco2009 Jan]气象牛Baric
Description 为了研究农场的气候,Betsy帮助农夫John做了N(1 <= N <= 100)次气压测量并按顺序记录了结果M_1...M_N(1 <= M_i <= ...
- bzoj 1576: [Usaco2009 Jan]安全路经Travel——并查集+dijkstra
Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数 ...
- bzoj 1575: [Usaco2009 Jan]气象牛Baric【dp】
完了不会dp了 设f[i][j]为以i结尾,有j个时的最优值,辅助数组g[i][j]为s选了i和j,i~j中的误差值 转移是f[j][i]=min(f[k][i-1]+g[k][j]) #includ ...
随机推荐
- IOS 开发学习33 使用sqlite3
sqlite3 命令行简单使用 sqlite3 路径 //打开数据库路径连接 select * from sqlite_master where type="table"; //显 ...
- vc 获取函数名称真实地址
首先写一个很简单的main函数: int main(){ printf("main的地址(?):%08x",main); } 单步调试,可得知 main函数的真实入口地址是:00b ...
- 【试水CAS-4.0.3】第01节_CAS服务端搭建及导入源代码到MyEclipse
完整版见https://jadyer.github.io/2015/07/16/sso-cas-server-demo/ /** * @see ---------------------------- ...
- 2019pycharm破解大法
通过激活码激活Pycharm 1 先找到你的hosts文件: Windows电脑:c:\windows\system32\drivers\etc Linux/Mac电脑:/etc 2 编辑hosts文 ...
- CSS3文本溢出
text-overflow: text-overflow:clip | ellipsis; clip:剪切多余的文字. ellipsis:文本溢出时显示省略标记. 要实现文本溢出剪切显示省略标记,还需 ...
- jconsole JDK1.6 使用手册 (转)
转载出处 文章作者:hornet 本文地址:http://hornetblog.sinaapp.com/?p=5 英文版地址: http://download.oracle.com/javase/6/ ...
- 移动端页面弹幕小Demo实例说明
代码地址如下:http://www.demodashi.com/demo/11595.html 弹幕小Demo实例地址,点击看效果 写在前面:尝试做了一下弹幕的实例,欢迎提出并指正问题 问题说明: D ...
- (MVC)从客户端中检测到有潜在危险的 Request.Form 值
在传统的.net Request验证中 ,只需要在WebConfig HttpRuntime节点 加入 RequestValidateMode 属性,值为2.0(此处2.0并非Framework版本) ...
- docker容器互连
三种方式 1.使用容器连接的示例如下: $ docker run --name some-app --link itbilu-mysql:mysql -d application-that-uses- ...
- .Net并行编程高级教程(二)-- 任务并行
前面一篇提到例子都是数据并行,但这并不是并行化的唯一形式,在.Net4之前,必须要创建多个线程或者线程池来利用多核技术.现在只需要使用新的Task实例就可以通过更简单的代码解决命令式任务并行问题. 1 ...