hdu+1595+删边最长最短路
来源:互联网 发布:java和go interface 编辑:程序博客网 时间:2024/05/17 02:13
开始我直接枚举删边 就超时,后来想了下,只要枚举最短路径上的边删除就行了。。。改了下 就AC了
#include<cstdio>#include<cstring>#include<queue>#include<algorithm>#include<set>using namespace std;const int inf=999999999;int n,m,cnt,a,b,l,dis[1010],in[1010],head[1010],mp[1010][1010];set<int>vt;struct EDGE{int y,l,nxt;}edge[1000010];void add(int x,int y,int l){edge[cnt].y=y;edge[cnt].l=l;edge[cnt].nxt=head[x];head[x]=cnt++;}void addedge(int x,int y,int l){add(x,y,l);add(y,x,l);}int spfa(int f){fill(dis,dis+n+1,inf);memset(in,0,sizeof(in));queue<int>q;q.push(1);in[1]=1;dis[1]=0;while(!q.empty()){int s=q.front();q.pop();in[s]=0;for(int j=head[s];j!=-1;j=edge[j].nxt){int y=edge[j].y,l=edge[j].l;if((j==f)||((j^1)==f))continue;if(dis[y]>dis[s]+l){dis[y]=dis[s]+l;if(!in[y]){in[y]=1;q.push(y);}}}}return dis[n];}void dfs(int x){if(x==1)return;for(int j=head[x];j!=-1;j=edge[j].nxt){int y=edge[j].y,l=edge[j].l;if(dis[y]+l==dis[x]){vt.insert(j);dfs(y);}}}int main(){while(~scanf("%d%d",&n,&m)){cnt=0;memset(head,-1,sizeof(head));memset(mp,0,sizeof(mp));for(int i=0;i<m;i++){scanf("%d%d%d",&a,&b,&l);if(a==b)continue;if(mp[a][b]==0){mp[a][b]=mp[b][a]=l;}elsemp[a][b]=min(mp[a][b],l);}for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++){if(mp[i][j]){addedge(i,j,mp[i][j]);}}int ans=0;spfa(-1);vt.clear();dfs(n);for(set<int>::iterator it=vt.begin();it!=vt.end();++it){ans=max(spfa(*it),ans);}printf("%d\n",ans);}return 0;}
- hdu+1595+删边最长最短路
- HDU 1595 find the longest of the shortest 删除一条边的最长最短路
- HDU 1595 find the longest of the shortest 删掉任意一条边的最长最短路
- HDU 1595 find the longest of the shortest 删掉任意一条边的最长最短路
- hdu 1595 最短路
- HDU 1595 find the longest of the shortest枚举+最短路(删掉任意一条边的最长最短路)★★
- HDU 1595 枚举+最短路(删掉边)
- 【hdu】2433 Travel【最短路删边】
- HDU 3986 Harry Potter and the Final Battle 删除一条边的最长最短路
- HDU 3986 Harry Potter and the Final Battle 删掉任意一条边的最长最短路
- 最短路最长路整理
- HDU 3986 Harry Potter and the Final Battle 删掉任意一条边的最长最短路(有重边)
- HDU - 1595 find the longest of the shortest(最短路Dijkstra+枚举删边)
- HDU 1595 find the longest of the shortest (最短路+记录路径+枚举删边)
- hdu1595(枚举+最短路(删掉任意一条边的最长最短路)-MB
- hdoj 1595 最短路中的最长路(good)
- HDU-1595&3986-枚举+最短路
- POJ 2253 Frogger(最长边最短路)
- yum的使用全解
- x86/x86_64 CPU控制寄存器(Control Registers)
- android和linux开源社区的分裂
- .C#中的委托是什么?事件是不是一种委托?
- char *、CString和string之间的类型转换 .
- hdu+1595+删边最长最短路
- 网速成为了工作的瓶颈之一
- 苹果开发者账号购买或续费支付表单填写全记录purchase form
- 《阅读一款3D引擎的方法备忘》
- 项目自动化之道-3.按键发布Ant版
- SQL SERVER 2008 高级注入 不支持单引号条件 显错模式
- 114啦源码之工具箱、名站切换栏修改
- ORACLE 统计分析
- hadoop---map/reduce中的一个坑