#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int dis[];
int visit[];
int SSSP[][];
void dijkstra(int x,int n)
{
int pos;
int minn;
for(int i=;i<=n;i++)
{
dis[i]=SSSP[][i];
}
visit[x]=;
dis[x]=;
for(int i=;i<=n;i++)
{
minn=INF;
pos=;
for(int j=;j<=n;j++)
{
if(!visit[j]&&dis[j]<minn)
{
pos=j;
minn=dis[j];
} }
if(pos==) break;
else
{
visit[pos]=;
for(int j=;j<=n;j++)
{
if(!visit[j]&& dis[pos]+SSSP[pos][j]<dis[j])
dis[j]=dis[pos]+SSSP[pos][j];
}
} }
}
int main()
{
while()
{
int n,m; cin>>n>>m;
if(n==&&m==) break; int zzzzz=; memset(visit,,sizeof(visit));
memset(dis,,sizeof(dis));
memset(SSSP,,sizeof(SSSP)); for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
SSSP[i][j]=INF;
}
int a[];
int b[];
int t[];
for(int i=;i<=m;i++)
{
cin>>a[i]>>b[i]>>t[i];
SSSP[a[i]][b[i]]=t[i];
SSSP[b[i]][a[i]]=t[i];
}
dijkstra(,n); //cout<<"*****"<<dis[n]<<"*******"<<zzzzz<<"******"<<endl;
if(dis[n]==INF)
{
zzzzz=;
}
int maxn=dis[n]; for(int i=;i<n;i++)
{
// qu dian chong ding yi
if(zzzzz==) break;
for(int j=;j<=n;j++)
{
for(int j1=;j1<=n;j1++)
SSSP[j][j1]=INF;
}
for(int j=;j<=m;j++)
{
SSSP[a[j]][b[j]]=t[j];
SSSP[b[j]][a[j]]=t[j];
if(a[j]==i||b[j]==i)
{
SSSP[a[j]][b[j]]=INF;
SSSP[b[j]][a[j]]=INF;
}
}
// chong ding yi visit[] dis memset(visit,,sizeof(visit));
memset(dis,,sizeof(dis)); dijkstra(,n); // cout<<"*****"<<dis[n]<<"*******"<<zzzzz<<"******"<<endl;
if(dis[n]==INF)
{
zzzzz=;
}
if(dis[n]>maxn) maxn=dis[n];
}
if(zzzzz==)
cout<<maxn<<endl;
if(zzzzz==)
cout<<"Inf"<<endl;
}
}

hdu5173 How Many Maos Does the Guanxi Worth的更多相关文章

  1. hdu 5137 How Many Maos Does the Guanxi Worth 最短路 spfa

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  2. HDU 5137 How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5120 ...

  3. hdoj 5137 How Many Maos Does the Guanxi Worth【最短路枚举+删边】

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  4. HDU5137 How Many Maos Does the Guanxi Worth(枚举+dijkstra)

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  5. How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  6. HDU 5137 How Many Maos Does the Guanxi Worth 最短路 dijkstra

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  7. (hdoj 5137 floyd)How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  8. 杭电5137How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  9. ACM学习历程——HDU5137 How Many Maos Does the Guanxi Worth(14广州10题)(单源最短路)

    Problem Description    "Guanxi" is a very important word in Chinese. It kind of means &quo ...

随机推荐

  1. 【Java算法】条件运算符

    利用条件运算符的嵌套来完成此题:学习成绩> =90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示. 条件运算符的表达式为: 表达式1?表达式2:表达式3 当表达式1为true ...

  2. windows 网络操作

    ver 命令 显示当前机器上的操作系统版本信息 ipconfig/release 释放IP地址 ipconfig/renew 重新获取IP地址 cmd下使用ssh 如果想在cmd中输入 ssh xx@ ...

  3. u-boot的内存分布

    cpu会自动从NAND flash 中读取前4KB的数据放置在片内SRAM里(s3c2440是soc),同时把这段片内SRAM映射到nGCS0片选的空间(即0x00000000).cpu是从0x000 ...

  4. python全栈开发笔记---基本数据类型--字符串魔法

    字符串: def capitalize(self, *args, **kwargs) test = "aLxs" v = test.capitalize() #capitalize ...

  5. Valgrind,内存调试工具

    Valgrind是一款用于内存调试.内存泄漏检测以及性能分析的软件开发工具 官网:http://valgrind.org/ 用户开发手册地址:http://valgrind.org/docs/manu ...

  6. idea 一些插件配置

    接触maven快2年了吧,对maven还是一知半解其实.得到了一些教训,就是少转牛角尖,多把握实际需要的东西,一口一口吃饭. 插件化很常见了.这里记录idea使用的jetty插件 和tomcat插件和 ...

  7. POJ 2407 Relatives(欧拉函数入门题)

    Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...

  8. request 的上传文件

    前言:注册接口需要上次头像,fiddle抓的接口如图,这个时候就需要用到:files 2,举例说明 a:有一个上传接口,地址如下:http://xx.xx.xx.xx//upload/stream b ...

  9. MySQL:MySQL Workbench的使用

    MySQL Workbench 一.布局介绍 附:图片转自https://blog.csdn.net/qq_19891827/article/details/53995079 二.创建数据库 第一步: ...

  10. setTimeout 与 闭包。。。

    先看下面一个比较坑的代码 for (var i=1; i<=5; i++) { setTimeout( function timer() { console.log(i); }, i*1000 ...