一次FLOYD,再枚举。

注意题目要求的输出是什么哦。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int inf=;
const int MAXN=;
int maze[MAXN][MAXN];
bool house[MAXN];
int dis[MAXN],fire,n; int main(){
int u,v,w;
while(scanf("%d%d",&fire,&n)!=EOF){
memset(house,false,sizeof(house));
for(int i=;i<MAXN;i++){
maze[i][i]=; dis[i]=inf;
for(int j=i+;j<MAXN;j++)
maze[i][j]=maze[j][i]=inf;
}
int station;
for(int i=;i<fire;i++){
scanf("%d",&station);
house[station]=true;
dis[station]=;
}
while(~scanf("%d%d%d",&u,&v,&w)){
maze[u][v]=maze[v][u]=min(w,maze[u][v]);
}
for(int k=;k<=n;k++){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(maze[i][k]+maze[k][j]<maze[i][j]){
maze[i][j]=maze[i][k]+maze[k][j];
}
}
}
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(house[j])
dis[i]=min(dis[i],maze[i][j]);
}
}
// for(int i=1;i<=n;i++)
// cout<<dis[i]<<endl;
int tmp,ans,s=inf;
for(int i=;i<=n;i++){
tmp=;
for(int j=;j<=n;j++){
tmp=max(min(dis[j],maze[i][j]),tmp);
}
if(tmp<s){
s=tmp; ans=i;
}
}
printf("%d\n",ans);
}
return ;
}

POJ 2607的更多相关文章

  1. POJ 2607 Fire Station(Floyd打表+枚举更新最优)

    题目链接: http://poj.org/problem?id=2607 Description A city is served by a number of fire stations. Some ...

  2. POJ 2607 Fire Station

    Fire Station Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on PKU. Original I ...

  3. poj和hdu部分基础算法分类及难度排序

    最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...

  4. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  7. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. bzoj2115

    线性基+dfs树 我们先搞出dfs树,其实最终路径就是最初的路径和一些环异或. 环最多只有m-n+1,因为一共有m条边,然后有n-1条边在dfs树上,所以还剩m-n+1条边,都可以构成环. 所以dfs ...

  2. glance rabbit

  3. org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.demo.pojo.IdCard

    转自:https://blog.csdn.net/zheng0518/article/details/11029733 TestStudent.testSchemaExporttestSchemaEx ...

  4. Cracking the Coding Interview 10.7

    Design an algorithm to find the kth number such that the only prime factors are 3,5 and 7 方法一: a[i]= ...

  5. A - Word

    Problem description Vasya is very upset that many people on the Net mix uppercase and lowercase lett ...

  6. JavaScript 判断手机端操作系统(Andorid/IOS)

    androidURL = "http://xxx/xxx.apk"; var browser = { versions: function() { var u = navigato ...

  7. Windows phone开发 网络编程之HttpWebRequest

    HttpWebRequest和WebClient的区别1,HttpWebRequest是个抽象类,所以无法new的,需要调用HttpWebRequest.Create();2,其Method指定了请求 ...

  8. 如何用js代码实现图片切换效果

    通过点击按钮,实现图片的隐藏与显现,切换. 实现代码:<style> .a{ width: 300px; height: 300px; border: 1px solid black; } ...

  9. 图片懒加载插件echo.js——改造

    今天做一个列表项需要用到懒加载,搜到网友推荐的echo.js,试用了一下,还不错.除了懒加载,还提供了throttle——节流,即用户快速滑动列表时,很快滑过的项的图片不会加载,只会加载最后停下来的位 ...

  10. cocos creator 底部按钮touch延迟

    cocos论坛里有这个问题: http://forum.cocos.com/t/ios-touchstart-bug/63367我的引擎版本:"engine_version": & ...