BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
3394: [Usaco2009 Jan]Best Spot 最佳牧场
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 11 Solved: 9
[Submit][Status]
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
- #include<cstdio>
- #include<cstdlib>
- #include<cmath>
- #include<cstring>
- #include<algorithm>
- #include<iostream>
- #include<vector>
- #include<map>
- #include<set>
- #include<queue>
- #include<string>
- #define inf 1000000000
- #define maxn 1000
- #define maxm 100000
- #define eps 1e-10
- #define ll long long
- #define pa pair<int,int>
- #define for0(i,n) for(int i=0;i<=(n);i++)
- #define for1(i,n) for(int i=1;i<=(n);i++)
- #define for2(i,x,y) for(int i=(x);i<=(y);i++)
- #define for3(i,x,y) for(int i=(x);i>=(y);i--)
- #define mod 1000000007
- using namespace std;
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
- return x*f;
- }
- struct edge{int go,next,w;}e[*maxm];
- int n,m,k,s,tot,a[maxn],b[maxn],q[maxn],d[maxn][maxn],head[maxn];
- bool v[maxn];
- void ins(int x,int y,int z)
- {
- e[++tot].go=y;e[tot].w=z;e[tot].next=head[x];head[x]=tot;
- }
- void insert(int x,int y,int z)
- {
- ins(x,y,z);ins(y,x,z);
- }
- void spfa(int s)
- {
- for(int i=;i<=n;++i) d[s][i]=inf;
- memset(v,,sizeof(v));
- int l=,r=,x,y;q[]=s;d[s][s]=;
- while(l!=r)
- {
- x=q[++l];if(l==maxn-)l=;v[x]=;
- for(int i=head[x];i;i=e[i].next)
- if(d[s][x]+e[i].w<d[s][y=e[i].go])
- {
- d[s][y]=d[s][x]+e[i].w;
- if(!v[y]){v[y]=;q[++r]=y;if(r==maxn-)r=;}
- }
- }
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- n=read();k=read();m=read();
- for1(i,k)a[i]=read();
- for1(i,m)
- {
- int x=read(),y=read(),z=read();
- insert(x,y,z);
- }
- for1(i,n)spfa(i);
- int ans=;
- for1(i,n)
- {
- for1(j,k)b[i]+=d[i][a[j]];
- if(b[i]<b[ans])ans=i;
- }
- printf("%d\n",ans);
- return ;
- }
BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场的更多相关文章
- 【BZOJ】3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)
http://www.lydsy.com/JudgeOnline/problem.php?id=3394 裸的floyd.. #include <cstdio> #include < ...
- bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MB Submit: 665 Solved: 227[Sub ...
- BZOJ3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 45 Solved: 27[Sub ...
- 1574: [Usaco2009 Jan]地震损坏Damage
1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 425 Solved: 232[Subm ...
- 3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 179 Solved: 73[Su ...
- 【BZOJ1576】[Usaco2009 Jan]安全路经Travel 最短路+并查集
[BZOJ1576][Usaco2009 Jan]安全路经Travel Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, ...
- 【思维题 并查集 图论】bzoj1576: [Usaco2009 Jan]安全路经Travel
有趣的思考题 Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第 ...
- [bzoj1574][Usaco2009 Jan]地震损坏Damage_dfs
地震损坏Damage bzoj-1574 Usaco-2009 Jan 题目大意:题目链接. 注释:略. 想法: 显然对于每一个report点,和它直接相连的点都不可能到达1.我们将它打上标记. 然后 ...
- BZOJ1576 [Usaco2009 Jan]安全路经Travel
首先用Dijkstra做出最短路生成树,设dis[p]为1到p点的最短路长度 对于一条不在生成树上的边u -> v,不妨设fa为u.v的lca 则一fa到v的路径上的任意点x都可以由u达到,走的 ...
随机推荐
- Effective C++ 第二版 40)分层 41)继承和模板 42)私有继承
条款40 通过分层来体现"有一个"或"用...来实现" 使某个类的对象成为另一个类的数据成员, 实现将一个类构筑在另一个类之上, 这个过程称为 分层Layeri ...
- Android Studio 2.1.x 关联SDK API Source
问题: 看图=>,当在android studio里ctrl+鼠标左键查看例如: TextUtils.isEmpty(content);这段代码的isEmpty方法的实现的时候经常就跑到如图所示 ...
- Neutron中的Service类
Service是OpenStack中非常重要的一个概念,各个服务的组件都以Service类的方式来进行交互. Neutron中的Service类继承自rpc中的Service,总体的继承关系为 neu ...
- android动画效果编程基础--Android Animation
动画效果编程基础--Android Animation 动画类型 Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 tran ...
- 【.NET特供-第三季】ASP.NET MVC系列:MVC与三层图形对照(颠覆性理论)
在[.NET特供-第三季]系列博客中的第一篇<ASP.NET MVC系列:MVC与三层图形对照>发表之后,引起了领导的注意.同一时候,开发小组内部在交流MVC和三层之间关系的 ...
- C#视频总结
C#视频利用了四天看完了,由于有VB的基础.所以看起来并没有感觉太吃力.在主要的数据类型.运算之间没有多大的差别. 在循环控制语句上也就是大同小异.在类.继承和多态方面可能有一些陌生,可是经过了前期的 ...
- 在MacOs上配置Hadoop和Spark环境
在MacOs上配置hadoop和spark环境 Setting up Hadoop with Spark on MacOs Instructions 准备环境 如果没有brew,先google怎样安装 ...
- HTML中常用的列表标签
- axure RP Pro7.0加载日历控件的步骤
- mysql 写数据操作几次硬盘?
mysql 写数据步骤: 1:写入操作事物日志,持久化操作日志到磁盘,并且只是写在磁盘上一小块区域内的顺序io,不需要像随机io一样 在磁盘多个地方移动磁头 2:内存中事物日志持久化以后 ,写入的数 ...