【BZOJ】3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)
2024-08-22 20:14:13
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
13 6 15
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
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
10
HINT
Source
最新文章
- C#之设计模式
- Oracle导出表(即DMP文件)的两种方法
- matrix-tree
- gym923B
- Javascript提升阶段学习
- SQL Server 诊断查询-(4)
- 逻辑回归的分布式实现 [Logistic Regression / Machine Learning / Spark ]
- (转)php的扩展和嵌入--php的生命周期与变量详述
- -_-#【Better JS Code】插入迭代值
- 两个string数组对应比较
- 基本event封装:阻止冒泡、默认事件等
- js模块化开发——require.js的用法详细介绍(含jsonp)
- 排序算法入门之希尔排序(java实现)
- PHP将汉字转为拼音
- STL标准模板类
- APM 原理与框架选型
- CVE-2017-12615和CVE-2017-12616
- (O)JS:执行环境、变量对象、活动对象和作用域链(原创)
- python的初始化运行了哪些?
- Unity3D 3D模型在GUI之上显示