hdu 5137 How Many Maos Does the Guanxi Worth(Dijkstra)
来源:互联网 发布:那的中超数据比较全 编辑:程序博客网 时间:2024/05/20 22:26
http://acm.hdu.edu.cn/showproblem.php?pid=5137
题目大意:
给出一个无向无环图,现在你有一个机会炸掉n个点其中的任意一个,只要炸掉这个点,那么这个点与其他但凡有连接的路径都会删除,问炸除一个点之后从 1–>n如果还有路径,那个最短路径是多少,如果没有路径,输出inf。
解题思路:
枚举每一个点,进行删点操作,之后进行求最短路,找出那个最短路最大值的那个点,删除之后即可。最后输出更新值。
#include<iostream>#include<cstring>#define INF 0x3f3f3f3f using namespace std;const int maxn=35;int n,g[maxn][maxn],s[maxn],d[maxn],vis[maxn];void Dijkstra(){ for(int i=1;i<=n;i++) d[i]=g[1][i]; memset(vis,0,sizeof(vis)); vis[1]=1; for(int i=1;i<=n;i++) { int mind=INF,mark; for(int j=1;j<=n;j++) if(!vis[j]&&mind>d[j]) mind=d[mark=j]; vis[mark]=1; for(int j=1;j<=n;j++) if(!vis[j]) d[j]=min(d[j],d[mark]+g[mark][j]); }}int main(){ int m; while(cin>>n>>m&&(n||m)) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) g[i][j]=(i==j)?0:INF; int ans=0,u,v,w,k; while(m--) { cin>>u>>v>>w; if(g[u][v]>w) g[u][v]=w; } for(int i=2;i<n;i++) { for(int j=1;j<=n;j++) { s[j]=g[i][j]; //先用一个数组存储好i->j的路径 g[i][j]=INF; //然后拆掉从i->j的路径 } Dijkstra(); //计算当前到n的最短路 ans=max(ans,d[n]); //不断更新那个拆了之后到n最短路值最大的那个 for(int j=1;j<=n;j++) //之后还原路径 g[i][j]=s[j]; } if(ans==INF) cout<<"Inf"<<endl; else cout<<ans<<endl; } return 0;}
阅读全文
0 0
- hdu 5137 How Many Maos Does the Guanxi Worth(dijkstra && floyd)
- HDU 5137 How Many Maos Does the Guanxi Worth(最短路--dijkstra)
- HDU:5137 How Many Maos Does the Guanxi Worth(dijkstra算法求最短路径+小技巧)
- hdu 5137 How Many Maos Does the Guanxi Worth(Dijkstra)
- How Many Maos Does the Guanxi Worth (dijkstra)
- Hdu oj 5137 How Many Maos Does the Guanxi Worth
- 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
- HDU 5137 How Many Maos Does the Guanxi Worth
- HDU-5137 H - How Many Maos Does the Guanxi Worth
- HDU 5137How Many Maos Does the Guanxi Worth
- hdu 5137 ( How Many Maos Does the Guanxi Worth )
- How Many Maos Does the Guanxi Worth HDU 5137 【Dijkstra算法+删去结点】
- hdu 5137 How Many Maos Does the Guanxi Worth(dijkstra算法+删边)
- HDUOJ_5137(dijkstra)(How Many Maos Does the Guanxi Worth)
- How Many Maos Does the Guanxi Worth (暴力枚举+Dijkstra)
- How Many Maos Does the Guanxi Worth
- HTML关于div的一些设置
- 利用JS实现动态进度条效果
- C++拷贝控制与资源管理
- Activity与Activity之间简单的数据传递
- 将List<Map>/Map中的key转换为驼峰规则
- hdu 5137 How Many Maos Does the Guanxi Worth(Dijkstra)
- C++邻接表与无向图
- 你所熟悉的Kafka
- 用链表构建学生信息库
- spring IOC控制反转及IOC实现的三种方式和bean标签使用
- 余承东回应华为P10“缩水门”事件,称“友商炒作丑化我们”
- ofo获富士达供应链产能加持 近期将宣布新轮融资
- C++邻接表与有向图
- 覃超点评F8大会:还是记忆中的Facebook,黑科技程度没两样 | 硬创公开课