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 : 我们要是每个城镇都是安全的:就是 ...
随机推荐
- bootstrap fileinput控件 + django后台上传、回显简单使用
一.控件下载:https://github.com/kartik-v/bootstrap-fileinput/ 官网:http://plugins.krajee.com/file-input 需要引入 ...
- BZOJ 2260 商店购物(最小树形图)
不会最小树形图的出门左转 其实如果确定每种商品第一件的购买顺序,那么剩下的商品肯定是以最优惠价格购买的. 如何确定各种商品第一件购买时的最小价值呢? 考虑如果购买了\(a_i\)这种商品,那么就能以\ ...
- [学习笔记] CS131 Computer Vision: Foundations and Applications:Lecture 4 像素和滤波器
Background reading: Forsyth and Ponce, Computer Vision Chapter 7 Image sampling and quantization Typ ...
- 使用tf.ConfigProto()配置Session运行参数和GPU设备指定
参考链接:https://blog.csdn.net/dcrmg/article/details/79091941 tf.ConfigProto()函数用在创建session的时候,用来对sessio ...
- LAMP 环境搭建备忘 -- Linux的安装(一)
LAMP指的是 Linux + Apatch + MySQL / MariaDB + PHP/Perl/Python 一套搭建网站服务器的开源软件组合.工作原理图如下: 下面开始环境搭建 1 Linu ...
- ES6之用let,const和用var来声明变量的区别
var(掌握) 不区分变量和常量 用var声明的变量都是变量,都是可变的,我们可以随便对它进行运算操作.这样当多个人进行同一个项目时,区分变量和常量会越来越难,一不小心就会把设计为常量的数据更改了 ...
- Python 绘图与可视化 matplotlib 填充fill和fill_between
参考链接:https://blog.csdn.net/You_are_my_dream/article/details/53457960 fill()填充函数曲线与坐标轴之间的区域: x = np.l ...
- web前端-移动端响应式与自适应
一. 在HTML的头部加入meta标签 在HTML的头部,也就是head标签中增加meta标签,告诉浏览器网页宽度等于设备屏幕宽度,且不进行缩放,代码如下: <meta name="v ...
- WinServer-IIS-IP及域的限制
如果启用域名限制,那么会对服务器产生比较大的资源开销,慎重选择这个 来自为知笔记(Wiz)
- POJ 1721
好像不需要用到开方什么的... 可以知道,一副牌即是一个循环,那么,由于GCD(L,K)=1,所以一次洗牌后,亦是一个循环.其实,K次洗牌等于是T^(2^K)了.既然是循环,必定有周期.那么,周期是多 ...