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

Sample Output

10

HINT

Source

最新文章

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

热门文章

  1. ssm整合(Spring+SpringMVC+Mybatis)
  2. 【Hibernate步步为营】--锁机制具体解释
  3. 基于Node.js + WebSocket 的简易聊天室
  4. PHP-客户端的IP地址伪造、CDN、反向代理、获取的那些事儿
  5. AngularJS实现简单的分页功能
  6. kettle--组件(3)--行转列
  7. Linux命令-网络命令:last
  8. PL/SQL 美化器不能解析文本
  9. NoSQL(二)
  10. rsync工具介绍