Luogu P2935 最好的地方Best Spot
Luogu P2935 最好的地方Best Spot
这道题就是一道近乎裸的Floyd,因为数据很小,所以用领接表存图就可以了。
#include<bits/stdc++.h>
#define INF 0x3fffffff
#define N 510
using namespace std;
int p,f,c,mmin=INF,sum,ans;
int like[N],e[N][N];
void Read() {
scanf("%d%d%d",&p,&f,&c);
for(int i=1;i<=p;i++) {
for(int j=1;j<=p;j++) {
e[i][j]=INF;
}
e[i][i]=0;
}
for(int i=1;i<=f;i++) {
scanf("%d",&like[i]);
}
for(int i=1;i<=c;i++) {
int a,b,t;
scanf("%d%d%d",&a,&b,&t);
e[a][b]=t;
e[b][a]=t;
}
return;
}
void Floyd() {
for(int k=1;k<=p;k++) {
for(int i=1;i<=p;i++) {
for(int j=1;j<=p;j++) {
e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
}
}
}
return;
}
void Print() {
for(int i=1;i<=p;i++) {
sum=0;
for(int j=1;j<=f;j++) {
sum+=e[i][like[j]];
}
if(sum<mmin) {
mmin=sum;
ans=i;
}
}
printf("%d",ans);
return;
}
int main()
{
Read();
Floyd();
Print();
return 0;
}
Luogu P2935 最好的地方Best Spot的更多相关文章
- 洛谷——P2935 [USACO09JAN]最好的地方Best Spot
P2935 [USACO09JAN]最好的地方Best Spot 题目描述 Bessie, always wishing to optimize her life, has realized that ...
- $P2935 [USACO09JAN]最好的地方Best Spot$
P2935 [USACO09JAN]最好的地方Best Spot Floyd的水题(黄题) 海星. 这可能是我第一道发的Floyd的博客 inline void Floyd(){ ;k<=n;k ...
- 洛谷 P2935 [USACO09JAN]最好的地方Best Spot
题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...
- [USACO09JAN]最好的地方Best Spot
OJ题号:洛谷2935 思路:Floyd #pragma GCC optimize ("O3") #include<cstdio> #include<cctype ...
- Luogu 魔法学院杯-第二弹(萌新的第一法blog)
虽然有点久远 还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题 沉迷游戏,伤感情 #include <queue> ...
- luogu p1268 树的重量——构造,真正考验编程能力
题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...
- URAL 1934 Black Spot(最短路)
Black Spot Time limit: 1.0 secondMemory limit: 64 MB Bootstrap: Jones's terrible leviathan will find ...
- [luogu P2170] 选学霸(并查集+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...
- [luogu P2647] 最大收益(贪心+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...
随机推荐
- html5 横向滑动导航栏
前提 需要引入: <script src="../assets/js/iscroll.js"></script> v4.2版本 ####html <! ...
- Django 操作已经存在的数据库
反向操作数据库 何为反向操作.即是数据库在项目之前已经存在,不需要新建表,操作已经存在的表 # 进入站点目录下执行 python manage.py inspectdb #可以看到settings中连 ...
- Error: python-devel conflicts with python-2.7.5-68.el7.x86_64
yum install yum-utils -y package-cleanup --cleandupes yum -y install python-devel yum -y install pyt ...
- JIRA+JIRA Agile敏捷项目管理工具
jira插件下载地址 http://www.confluence.cn/pages/viewpage.action?pageId=1671327 下载GreenHopper插件 安装Jira-agil ...
- [转载]SQL Server提权系列
本文原文地址:https://www.cnblogs.com/wintrysec/p/10875232.html 一.利用xp_cmdshell提权 xp_cmdshell默认是关闭的,可以通过下面的 ...
- 原生xgboost中如何输出feature_importance
网上教程基本都是清一色的使用sklearn版本,此时的XGBClassifier有自带属性feature_importances_,而特征名称可以通过model._Booster.feature_na ...
- [NPM错误]npm ERR! Unexpected end of JSON input while parsing near ‘’
[错误描述] npm ERR! Unexpected end of JSON input while parsing near ‘ ’ [前提描述] 在安装vue2-editor时,中断暂停了,再次 ...
- Ubuntu下U盘文件只读的解决办法
转自linux公社:http://www.linuxidc.com/Linux/2012-12/76130.htm Ubuntu下U盘出现文件系统只读的问题了.症状为无法删除U盘中现有文件,无法向U盘 ...
- Djang简单使用
用户访问内容 用户能够访问的所有的资源,都是程序猿提前暴露的,如果没有暴露,用户是不能进行访问的. diango重启的问题 当我们更改django中的代码的时候,django内部会检测到我们更 ...
- python3快速安装升级pip3
一.下载地址: 获取get-pip.py安装文件: 官网链接:https://bootstrap.pypa.io/get-pip.py 百度云链接:https://pan.baidu.com/s/14 ...