#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. sql2008r2安装失败的解决办法

    setup fails with: '.', hexadecimal value 0x00, is an invalid character.SQL 2012 Setup issues - hexad ...

  2. 重写equals() 和 hashCode()方法

    什么情况下需要重写呢? 比如去重操作时, 有时候往Set集合存放对象User,我们User类的字段太多时,比如有50个字段, 判断两个User对象相同,不需要判断它们所有字段都相同,只需要判断它们的某 ...

  3. js如何生成一个对象,并转化为json字符串

    js如何生成一个对象,并转化为json字符串,很多人都会误写为: var ary = []; var obj = {}; for (var i = 0; i < 3; i++) { obj.na ...

  4. 安装gcc

    yum -y install gcc yum -y install gcc-c++ yum install make   -- 或者 yum groupinstall "Developmen ...

  5. EF code first Mysql 更换主键类型

    把主键从long 改为int 居然要删掉重建,不知道有没有更好的办法. 删除带外键的表: Add-Migration name 修改生成的文件,主要把dbo.删除 然后update-database

  6. shiro学习笔记(四) ini配置以及加解密

    INI配置 从之前的Shiro架构图可以看出,Shiro是从根对象SecurityManager进行身份验证和授权的:也就是所有操作都是自它开始的,这个对象是线程安全且真个应用只需要一个即可,因此Sh ...

  7. Linux 安装最新版本python3

    新安装了Linux系统(CentOS 6),发现已安装的python版本是2.6. 在网上搜索研究之后总结了一下怎么在保留python2的同时安装最新版的python3. 1. 查看 Python 的 ...

  8. Beta阶段冲刺---Day2

    一.Daily Scrum Meeting照片 二.今天冲刺情况反馈 1.昨天已完成的工作· 题目切换的改进· 支持退格操作 2.今天计划完成的工作· 数字以扑克牌的形式给出· 答案的乘除符号与游戏中 ...

  9. 4-log4j2之切分日志文件

    一.添加maven依赖 <dependencies> <dependency> <groupId>org.apache.logging.log4j</grou ...

  10. kbmMW SmartService控制返回类型