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 : 我们要是每个城镇都是安全的:就是 ...
随机推荐
- 浅谈自底向上的Shell脚本编程及效率优化
作者:沐星晨 出处:http://blog.csdn.net/sosodream/article/details/6276758 浅谈自底向上的Shell脚本编程及效率优化 小论文,大家多批评指导:) ...
- laravel 知识点总结
1.eloquent 关系理解: https://lvwenhan.com/laravel/423.html
- NotFoundHttpException
报错:NotFoundHttpException 这种一般都是路由配置错误
- 查看系统进程:ps、top
1.ps命令:提供最近进程的快照.显示当前活跃进程的简要信息. 常见使用: (1)与grep命令配合查找是否有相应进程存活 ps -ef | grep ksmd ps -Af | grep ksmd ...
- myeclipse的git插件安装
首先需要一个myeclies的Git插件EGit 点击下载5.0.1 官方网站
- rpm方式在centos7中安装mysql
.安装MySQL server 首先下载好mysql的rpm安装包 使用rpm命令安装: rpm -ivh MySQL-server--.glibc23.i386.rpm #rpm -ivh MySQ ...
- C#调用带结构体指针的C Dll的方法【转】
发现一篇文章关于C#调用DALL动态链接库的函数的,复制下来学习用.感谢作者的分析,原文传送门:https://www.cnblogs.com/ye-ming/p/8004314.html 在C#中调 ...
- java方法名的重载
方法的重载:方法名相同,参数不同,按照参数类型进行匹配 创建一个Simple 类,然后定义了两个方法 package cuteSnow; public class Simple { // 方法的重载, ...
- 在Action中获取servlet API
Struts2的Action组件是不依赖servlet API 的.那么当你在action中的业务需要处理HttpServletRequest和HttpServletResponse的时候(比如要对响 ...
- http响应的封装
响应的封装: 资源的初始化 分析请求响应信息,根据状态响应码,发送不同的状态码 浏览器根据状态信息,做出不同的执行 构建正文,也就是根据浏览器客服端的请求发送响应信息: 发送响应:code 是状态码, ...