poj 2607 Fire Station
来源:互联网 发布:淘宝运营计划表 编辑:程序博客网 时间:2024/05/01 12:03
枚举点求单源最短路
Memory: 748K Time: 204MSLanguage: G++ Result: Accepted
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<queue>using namespace std;const int maxn=505;const int INF=0x3fffffff;struct node{ int v, w, next;}edge[maxn*40];int n, m, pre[maxn], inqueue[maxn], cnt, fire[maxn], d[maxn], dmin[maxn], vis[maxn];void add_edge(int s, int e, int w){ edge[cnt].v=e; edge[cnt].w=w; edge[cnt].next=pre[s]; pre[s]=cnt++;}int max(int x, int y){return x>y?x:y;}int min(int x, int y){return x<y?x:y;}void init(){ int i, x, y, w; cnt=0; memset(vis, 0, sizeof(vis)); memset(pre, -1, sizeof(pre)); for(i=0; i<m; i++){ scanf("%d", &fire[i]); vis[fire[i]]=1; } while(scanf("%d%d%d", &x, &y, &w)!=EOF){ add_edge(x, y, w); add_edge(y, x, w); }}void spfa(int st){ queue<int > q; memset(inqueue, 0, sizeof(inqueue)); for(int i=1; i<=n; i++) d[i]=INF; d[st]=0; q.push(st); inqueue[st]=1; int head, s; while(!q.empty()){ head=q.front(); inqueue[head]=0; q.pop(); for(s=pre[head];s!=-1;s=edge[s].next){ if(d[edge[s].v]>d[head]+edge[s].w){ d[edge[s].v]=d[head]+edge[s].w; inqueue[edge[s].v]=1; q.push(edge[s].v); } } }}void solve(){ int i, j, ans=0, loc=1, tmp; for(i=1; i<=n; i++)dmin[i]=INF; for(i=0; i<m; i++){ spfa(fire[i]); for(j=1; j<=n; j++) if(dmin[j]>d[j]) dmin[j]=d[j]; } for(i=1; i<=n; i++)if(dmin[i]>ans)ans=dmin[i]; for(i=1; i<=n; i++){ if(!vis[i]){ tmp=0; spfa(i); for(j=1; j<=n; j++) tmp=max(tmp, min(dmin[j], d[j])); if(tmp<ans){ ans=tmp; loc=i; } } } printf("%d\n", loc);}int main(){ //freopen("1.txt", "r", stdin); scanf("%d%d", &m, &n); init(); solve(); return 0;}
- POJ 2607 Fire Station
- poj 2607 Fire Station
- poj 2607 Fire Station
- POJ 2607 Fire Station
- poj 2607 Fire Station
- poj 2607 Fire Station(floyd)
- POJ 2607 / ZOJ 1857 /NYOJ210 Fire Station
- POJ 2607 ZOJ 1857 Fire Station
- ZOJ 1857 && POJ 2607 Fire Station【SPFA】
- POJ 2607 Fire Station(floyd)
- ZOJ-1857(POJ-2607) Fire Station
- poj 2607 Fire Station (spfa)
- POJ 2607 Fire Station(Floyd)
- POJ 2607 Fire Station 消防站
- POJ 2607 / ZOJ 1857 Fire Station (临接表+spfa)
- zoj 1857 || poj 2607 Fire Station(纠结!!!)
- Fire Station
- Fire Station
- 黑马程序员_css study notes(Sorted from w3cschool)1
- 黑马程序员_css study notes(Sorted from w3cschool)2
- Unix环境程序之进程
- windows XP下MySQL Cluster集群安装配置
- LINUX JDK 安装与环境变量设置
- poj 2607 Fire Station
- JS 计算百分
- tiny210 android 编译分析
- MySQL Cluster 详细配置文件(config.ini)
- _stprintf
- 在FORTRAN程序中使用shell命令
- FPGA开发软件问题 详解
- SendMessage和PostMessage的用法
- 非vip用户下载虾米音乐的方法