POJ 2607 Fire Station
Fire Station
This problem will be judged on PKU. Original ID: 2607
64-bit integer IO format: %lld Java class name: Main
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
Output
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的更多相关文章
- POJ 2607 Fire Station(Floyd打表+枚举更新最优)
题目链接: http://poj.org/problem?id=2607 Description A city is served by a number of fire stations. Some ...
- Nyoj Fire Station
描述A city is served by a number of fire stations. Some residents have complained that the distance fr ...
- POJ 2152 fire / SCU 2977 fire(树型动态规划)
POJ 2152 fire / SCU 2977 fire(树型动态规划) Description Country Z has N cities, which are numbered from 1 ...
- POJ 2607
一次FLOYD,再枚举. 注意题目要求的输出是什么哦. #include <iostream> #include <cstdio> #include <cstring&g ...
- [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 ...
- poj - 4045 - Power Station
题意:一棵有n个结点的树,要取其中的一个结点,使得该结点到其他所有结点的距离和dis最小,即损耗I * I * R * dis最小,输出最小损耗和该结点(有多个的话按结点编号从小到大输出)(3 < ...
- POJ 2152 Fire(树形dp)
http://poj.org/problem?id=2152 题意: n个节点组成的树,要在树一些点上建立消防站,每个点建站都有个cost[i],每个点如果不在当前的点上建站,也要依赖其他的消防站,并 ...
- POJ 2152 Fire(树形DP)
题意: 思路:令F[i][j]表示 的最小费用.Best[i]表示以i为根节点的子树多有节点都找到负责消防站的最小费用. 好难的题... #include<algorithm> #incl ...
- POJ 2152 Fire
算是我的第一个树形DP 的题: 题目意思:N个城市形成树状结构.现在建立一些消防站在某些城市:每个城市有两个树形cost(在这个城市建立消防站的花费),limit : 我们要是每个城镇都是安全的:就是 ...
随机推荐
- pytorch 7 save_reload 保存和提取神经网络
import torch import matplotlib.pyplot as plt # torch.manual_seed(1) # reproducible # fake data x = t ...
- mysql存储小数
线下不知道什么版本的古董了,经本人亲测,varchar类型的数据,可以直接执行mysql的sum函数. ________________________________________________ ...
- COGS——T 2342. [SCOI2007]kshort || BZOJ——T 1073
http://www.cogs.pro/cogs/problem/problem.php?pid=2342 ★★☆ 输入文件:bzoj_1073.in 输出文件:bzoj_1073.out ...
- 查看系统的I/O使用iostat命令而使用iotop能够依据I/O统计信息排序,追踪到详细的进程
当看到I/O等待时间所占CPU时间的比重非常高的时候,首先要检查的就是机器是否正在大量使用交换空间,由于硬盘操作的速度远远低于RAM.所以当系统内存耗尽,開始使用交换空间的时候.系统的性能会受到严重影 ...
- 拷贝构造函数不能传值,只能传引用,而且一般是传const引用
为什么呢?因为传值函数,需要调用拷贝构造函数,那就层层循环无止境了.
- HDU 4312 Contest 2
题目要求两点间的最大值作为距离即: 即是切比雪夫距离.而切比雪夫距离与曼哈顿距离的转换却很巧妙. 把平面坐标所有点绕原点逆向旋转45度后,所得点的曼哈顿距离之和除以√2,即是切雪比夫距离.旋转点的公式 ...
- ZOJ 3556
终于做出来了,激动.... 这道题隐藏得深啊,但若推导下来,就变简单了. 首先,一个集合的子集的个数为2^n=s.注意了,题目求的是有序集合组,并且每个集合是可以重复使用的,怎么办呢?这就要想到多重集 ...
- hdoj 4548 美素数 【打表】
另类打表:将从1到n的满足美素数条件的数目赋值给prime[n],这样最后仅仅须要用prime[L]减去prime[R-1]就可以: 美素数 Time Limit: 3000/1000 MS (Jav ...
- D3D 线列 小样例
画两条线 #pragma once #pragma comment(lib,"d3d9.lib") #pragma comment(lib,"d3dx9.lib" ...
- (转)C/C++ 宏详解
众多C++书籍都忠告我们C语言宏是万恶之首,但事情总不如我们想象的那么坏,就如同goto一样.宏有一个很大的作用,就是自动为我们产生代码.如果说模板可以为我们产生各种型别的代码(型别替换),那么宏其实 ...