Fire Station

Time Limit: 5000ms
Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 2607
64-bit integer IO format: %lld      Java class name: Main

 
A city is served by a number of fire stations. Some residents have complained that the distance from their houses to the nearest station is too far, so a new station is to be built. You are to choose the location of the fire station so as to reduce the distance to the nearest station from the houses of the disgruntled residents. 
The city has up to 500 intersections, connected by road segments of various lengths. No more than 20 road segments intersect at a given intersection. The location of houses and firestations alike are considered to be at intersections (the travel distance from the intersection to the actual building can be discounted). Furthermore, we assume that there is at least one house associated with every intersection. There may be more than one firestation per intersection.

 

Input

The first line of input contains two positive integers: f,the number of existing fire stations (f <= 100) and i, the number of intersections (i <= 500). The intersections are numbered from 1 to i consecutively. f lines follow; each contains the intersection number at which an existing fire station is found. A number of lines follow, each containing three positive integers: the number of an intersection, the number of a different intersection, and the length of the road segment connecting the intersections. All road segments are two-way (at least as far as fire engines are concerned), and there will exist a route between any pair of intersections.

 

Output

You are to output a single integer: the lowest intersection number at which a new fire station should be built so as to minimize the maximum distance from any intersection to the nearest fire station.

 

Sample Input

1 6
2
1 2 10
2 3 10
3 4 10
4 5 10
5 6 10
6 1 10

Sample Output

5

Source

 
解题:枚举最短路,坑爹,居然文件结束输入路径
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
const int maxn = ;
struct arc{
int to,cost,next;
arc(int x = ,int y = ,int z = -){
to = x;
cost = y;
next = z;
}
};
arc e[maxn*maxn];
int head[maxn],d[maxn],dd[maxn];
int tot,n,m;
bool done[maxn];
void add(int u,int v,int w){
e[tot] = arc(v,w,head[u]);
head[u] = tot++;
e[tot] = arc(u,w,head[v]);
head[v] = tot++;
}
void dijkstra(int s,int *d){
for(int i = ; i <= n; ++i) done[i] = false;
d[s] = ;
priority_queue< pii,vector< pii >,greater< pii > >q;
q.push(make_pair(d[s],s));
while(!q.empty()){
int u = q.top().second;
q.pop();
if(done[u]) continue;
done[u] = true;
for(int i = head[u]; ~i; i = e[i].next){
if(d[e[i].to] > d[u] + e[i].cost){
d[e[i].to] = d[u] + e[i].cost;
q.push(make_pair(d[e[i].to],e[i].to));
}
}
}
}
int main(){
while(~scanf("%d %d",&m,&n)){
int fire[maxn],tmp,u,v,w;
bool isfire[maxn] = {false};
memset(head,-,sizeof(head));
for(int i = tot = ; i < m; ++i){
scanf("%d",&tmp);
fire[i] = tmp;
isfire[tmp] = true;
}
while(~scanf("%d %d %d",&u,&v,&w)) add(u,v,w);
for(int i = ; i <= n; ++i) d[i] = INF;
for(int i = ; i < m; ++i) dijkstra(fire[i],d);
int maxv = INF,index = ;
for(int i = ; i <= n; ++i){
if(isfire[i]) continue;
memcpy(dd,d,sizeof(d));
dijkstra(i,dd);
int mmxx = ;
for(int k = ; k <= n; ++k)
mmxx = max(mmxx,dd[k]);
if(mmxx < maxv){
index = i;
maxv = mmxx;
}
}
printf("%d\n",index);
}
return ;
}

POJ 2607 Fire Station的更多相关文章

  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. Nyoj Fire Station

    描述A city is served by a number of fire stations. Some residents have complained that the distance fr ...

  3. POJ 2152 fire / SCU 2977 fire(树型动态规划)

    POJ 2152 fire / SCU 2977 fire(树型动态规划) Description Country Z has N cities, which are numbered from 1 ...

  4. POJ 2607

    一次FLOYD,再枚举. 注意题目要求的输出是什么哦. #include <iostream> #include <cstdio> #include <cstring&g ...

  5. [ACM_搜索] POJ 1096 Space Station Shielding (搜索 + 洪泛算法Flood_Fill)

    Description Roger Wilco is in charge of the design of a low orbiting space station for the planet Ma ...

  6. poj - 4045 - Power Station

    题意:一棵有n个结点的树,要取其中的一个结点,使得该结点到其他所有结点的距离和dis最小,即损耗I * I * R * dis最小,输出最小损耗和该结点(有多个的话按结点编号从小到大输出)(3 < ...

  7. POJ 2152 Fire(树形dp)

    http://poj.org/problem?id=2152 题意: n个节点组成的树,要在树一些点上建立消防站,每个点建站都有个cost[i],每个点如果不在当前的点上建站,也要依赖其他的消防站,并 ...

  8. POJ 2152 Fire(树形DP)

    题意: 思路:令F[i][j]表示 的最小费用.Best[i]表示以i为根节点的子树多有节点都找到负责消防站的最小费用. 好难的题... #include<algorithm> #incl ...

  9. POJ 2152 Fire

    算是我的第一个树形DP 的题: 题目意思:N个城市形成树状结构.现在建立一些消防站在某些城市:每个城市有两个树形cost(在这个城市建立消防站的花费),limit : 我们要是每个城镇都是安全的:就是 ...

随机推荐

  1. Chrome Is The New C Runtime

    出处:https://www.mobilespan.com/content/chrome-is-the-new-c-runtime Chrome Is The New C Runtime Date:  ...

  2. Django -查询数据库相关操作

    一. 内置Admin 依赖APP: django.contrib.auth django.contrib.contenttypes django.contrib.messages django.con ...

  3. Libvirt中windows虚拟机的动态内存管理

    非常短的前提 Libvirt支持对虚拟机进行内存动态扩展,可是windows虚拟机首先须要安装virtio-win驱动. KVM提供的virtio-win驱动下载地址: http://www.linu ...

  4. 基于redis ae实现 Linux中的文件系统监控机制(inotify)

    (英文部分为转的.代码是个人代码) 1 What's inotify  The inotify API provides a mechanism for monitoring file system ...

  5. int *p,cons int *p,int const *p,int * const p,const int * const p,int const * const p的差别

     加有constkeyword的几种情况的辨析 const修饰的代码 含义(特点) 等价性 int *p = &num; 1.       能够读自己 2.       能够通过*p改自己 ...

  6. CC2540/CC2541 : Set the Peripheral Being Advertising while It is Being Connected

    There is possible to set your CC254X be scanable when it is in connection. But, based on my test,the ...

  7. 蓝桥杯 - 带分数 (DFS)

      历届试题 带分数   时间限制:1.0s   内存限制:256.0MB        问题描写叙述 100 能够表示为带分数的形式:100 = 3 + 69258 / 714. 还能够表示为:10 ...

  8. 百度地图-----&gt;地图类型、定位模式、实时交通、我的位置、加入覆盖物、覆盖物详情及提示

    在百度地图开发平台 http://developer.baidu.com/map/index.php? title=androidsdk 进行创建应用,获取应用的AK,在进行下载BaiduLBS_An ...

  9. LeetCode -- 求字符串数组中的最长公共前缀

    题目描写叙述: Write a function to find the longest common prefix string amongst an array of strings.就是给定1个 ...

  10. UVALive 4223 / HDU 2962 spfa + 二分

    Trucking Problem Description A certain local trucking company would like to transport some goods on ...