hdu1595 find the longest of the shortest
来源:互联网 发布:win8.1极速精简优化版 编辑:程序博客网 时间:2024/04/26 20:53
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define inf 0x3f3f3f3f#define ll __int64using namespace std;int mp[1010][1010],d[1010],vis[1010],next[1010],n,m,flag,ans;void dij(int s){ int i,j,tmp,p; memset(vis,0,sizeof vis); memset(d,0x3f,sizeof d); d[s]=0; for(i=1;i<=n;i++) { tmp=inf;p=0; for(j=1;j<=n;j++) { if(!vis[j]&&tmp>d[j]) { tmp=d[j]; p=j; } } if(tmp==inf) return ; vis[p]=1; for(j=1;j<=n;j++) { if(!vis[j]) { if(tmp+mp[p][j]<d[j]) { d[j]=tmp+mp[p][j]; if(flag) next[j]=p; } } } }}int main(){ int i,j,u,v,w,tmp; while(~scanf("%d%d",&n,&m)) { for(i=0;i<=n;i++) for(j=0;j<=n;j++) if(i!=j) mp[i][j]=inf; else mp[i][j]=0; for(i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&w); mp[u][v]=mp[v][u]=min(w,mp[v][u]); } flag=1; memset(next,0,sizeof next); dij(1); ans=d[n];flag=0; for(i=n;i!=1;i=next[i]) { tmp=mp[i][next[i]]; mp[i][next[i]]=mp[next[i]][i]=inf; dij(1); if(d[n]>ans) ans=d[n]; mp[i][next[i]]=mp[next[i]][i]=tmp; } printf("%d\n",ans); } return 0;}
0 0
- hdu1595-find the longest of the shortest
- HDU1595---find the longest of the shortest
- hdu1595 find the longest of the shortest
- HDU1595 find the longest of the shortest
- HDU1595 find the longest of the shortest
- find the longest of the shortest HDU1595
- HDU1595:find the longest of the shortest(Dijkstra)
- hdu1595 find the longest of the shortest(Dijkstra)
- HDU1595:find the longest of the shortest(Dijkstra)
- hdu1595(spfa) find the longest of the shortest
- HDU1595 find the longest of the shortest(最短路)
- HDU1595 find the longest of the shortest(最短路,Dijkstra)
- hdu1595 find the longest of the shortest (dijkstra+记录路径)
- hdu1595—find the longest of the shortest(dijkstra+枚举)
- HDU1595 find the longest of the shortest(dijk+路径记录+枚举)
- HDU1595:find the longest of the shortest(spfa+记录路径)
- find the longest of the shortest
- find the longest of the shortest HDU
- 第5周实验:GUI编程及JDK API的使用
- 黑马程序员_集合
- 第四周作业,图的表示
- Windows Server 2008 DNS服务器安装与配置
- 消息队列之JMS和AMQP对比
- hdu1595 find the longest of the shortest
- Java bytecode library
- 强连通,缩点,然后统计出入度
- Poj 1459 Power Network 最大流
- 为什么说 Git 比 SVN 更好
- DP_石子合并问题
- xp 与 ubuntu 双系统卸载linux
- 经典排序算法之归并排序
- 黑马程序员 第21天 异常概述