HDU 5137 How Many Maos Does the Guanxi Worth(最短路)
来源:互联网 发布:软件开发管理名词解释 编辑:程序博客网 时间:2024/05/16 17:56
题目:点击打开链接
题意:一个人要从1走到n,你的任务是尽可能的阻止他,通过1到n之间删除某一个点(不包括起点1和终点n),如果能够通过删除一个点使得这个人走不到n,则输出Inf;不能,则尽可能让这个人花费大的价值走到n(当然这个人肯定不傻他会选择最短路去走),输出这个最大价值。
思路:每次删除一个点,即给与该点相关的所有边的权值赋值为inf,然后进行一遍dijkstra最短路,更新最短路的最大值即可。这道题没有一遍A掉的原因:1.初始化没初始化好,2.这是一个无向图而不是有向图。
代码:
#include <iostream>#include <bits/stdc++.h>using namespace std;const int maxv=33;const int inf=0x3f3f3f3f;struct sa{ int u,v;}e[3003];int d[maxv];bool used[maxv];int n,m;int cost[maxv][maxv],tmp[maxv][maxv];void dijkstra(int s){ for(int i=1;i<=n;i++) { d[i]=inf; used[i]=false; } d[s]=0; while(true) { int v=-1; for(int u=1;u<=n;u++) { if(used[u]==false&&(v==-1||d[u]<d[v])) v=u; } if(v==-1) break; used[v]=true; for(int u=1;u<=n;u++) { d[u]=min(d[u],d[v]+cost[v][u]); } }}int main(){ while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cost[i][j]=inf; for(int i=0;i<m;i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); cost[u][v]=w; cost[v][u]=w; e[i].u=u; e[i].v=v; } int ans=0; for(int i=2;i<=n-1;i++) { for(int j=1;j<=n;j++) { tmp[i][j]=cost[i][j]; tmp[j][i]=cost[j][i]; cost[i][j]=inf; cost[j][i]=inf; } dijkstra(1); ans=max(ans,d[n]); for(int j=1;j<=n;j++) { cost[i][j]=tmp[i][j]; cost[j][i]=tmp[j][i]; } } if(ans>=inf) printf("Inf\n"); else printf("%d\n",ans); } return 0;}
阅读全文
0 0
- hdu 5137 How Many Maos Does the Guanxi Worth (最短路SPAF实现)
- HDU 5137 How Many Maos Does the Guanxi Worth(最短路--dijkstra)
- HDU 5137 How Many Maos Does the Guanxi Worth (最短路)
- HDU 5137 How Many Maos Does the Guanxi Worth(最短路)
- HDU 5137 How Many Maos Does the Guanxi Worth (14广州 Floyd 最短路)
- HDU 5137--How Many Maos Does the Guanxi Worth【枚举 && 最短路 && spfa】
- HDU 5137 How Many Maos Does the Guanxi Worth (Floyd 最短路)
- hdu 5137 How Many Maos Does the Guanxi Worth(最短路)
- -----最短路 最大值 hdu 5137-How Many Maos Does the Guanxi Worth
- 【最短路】HDU5137 How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth 5137 (最短路+删点+最大边)
- HDOJ 5137 How Many Maos Does the Guanxi Worth(最短路)
- 杭电-5137How Many Maos Does the Guanxi Worth(删点枚举+最短路)
- HDU 5137 How Many Maos Does the Guanxi Worth(删点最短路)
- 2014广州现场赛/HDU 5137 How Many Maos Does the Guanxi Worth(删点最短路)
- hdu 5137 How Many Maos Does the Guanxi Worth(最短路径)
- HDU 5137 How Many Maos Does the Guanxi Worth(最短路径)
- HDU 5137 How Many Maos Does the Guanxi Worth(枚举+最短路径)
- Java6:多态
- hexo init时出现 ERROR Local hexo not found in D:\Hexo
- 105_容器_Map和HashMap的基本用法_HashMap和HashTable的区别
- tf.transpose
- Android 系统调用实现函数功能--SVC指令的实现与检测
- HDU 5137 How Many Maos Does the Guanxi Worth(最短路)
- 架构师之路--视频业务介绍,离线服务架构和各种集群原理
- Docker实现一个Redis cluster
- (十一)ODataModel数据交互
- Windows下安装Tensorflow步骤
- 个人java学习回顾02
- Windows系统如何查IP和DNS
- 云服务器上tomcat启动后,外网访问很慢的解决办法
- 编程题(顺时针旋转矩阵)