一次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. 动态规划---状压dp

    状压dp,就是把动态规划之中的一个个状态用二进制表示,主要运用位运算. 这里有一道例题:蓝书P639猛兽军团1 [SCOI2005]互不侵犯 题目: 题目描述 在N×N的棋盘里面放K个国王,使他们互不 ...

  2. How to add dependency on a Windows Service AFTER the service is installed

    his can also be done via an elevated command prompt using the sc command. The syntax is: sc config [ ...

  3. LA4788

    贪心 这个贪心不太懂啊 dfs返回子树需要的最小值,然后按需要减消耗排序,然后贪心选取即可. #include<bits/stdc++.h> using namespace std; ty ...

  4. 新建项目git clone

  5. selenium3 + python - alert_is_present定位

    from selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium ...

  6. 点开,看一段,你就会喜欢上学习pandas,你该这么学!No.3

    身为一个啰嗦的博主,还是要说点啥,如果你不想学,直接拖拽到最后,发现彩蛋,然后3秒 我呢,有个小目标,就是把技术类的文章,写的有趣 编程呢,最难的是什么? 我投票给入门 其实,把一个人带进编程的大门是 ...

  7. IO流遍历文件夹下所有文件问题

    import java.io.File; /** * @author 王恒 * @datetime 2017年4月20日 下午2:24:32 * @description 递归调用 * */ publ ...

  8. 大白话理解promise对象

    Promise  代表了未来某个将要发生的事件(通常是一个异步操作)  Promise 是异步编程的解决方案,能够简化多层回调嵌套,代表了未来某个将要发生的事件.Promise是一个构造函数,本身有a ...

  9. Spring boot -环境搭建 ,初步接触(1)

    1. Eclipse 创建 maven project  项目目录如下: 2. pom.xml  配置文件 <project xmlns="http://maven.apache.or ...

  10. Css打造一个简单的静态七巧板

    偶然在微博上看到用css写一个七巧板,正好也有一些源代码,于是就试着敲了敲. 主要是利用了css3的transform,实现平移,旋转,变形,直接用看到的代码敲出来之后有些问题,因为宽度上下面绿色的三 ...