#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. linux 播放加密DVDs

    尝试下 https://www.cyberciti.biz/faq/howto-ubuntu-linux-playback-dvd/

  2. js 小说格式整理

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  3. Java单例模式《二》懒汉式

    package com.study.mode; /** * 单例模式: 懒汉式,需要的时候创建. * @ClassName: SingleBean2 * @author BlueLake * @dat ...

  4. day14-python异常处理

    1.     异常 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在Python无法正常处理程序时就会发生一个异常.异常是Python对象,表示一个错误.当Pyt ...

  5. urllib python3 请求、登录、下载网页

    urllib.request 发送request和获取request的结果 urllib.error包含了urllib.request产生的异常 urllib.parse用来解析和处理Url urll ...

  6. :工厂模式1:方法模式--Pizza

    #ifndef __PIZZA_H__ #define __PIZZA_H__ class Pizza { public: Pizza(){} virtual ~Pizza(){} virtual c ...

  7. 依赖倒置(DIP)、控制反转(IOC)和依赖注入(DI)

    原文: https://blog.csdn.net/briblue/article/details/75093382 写这篇文章的原因是这两天在编写关于 Dagger2 主题的博文时,花了大量的精力来 ...

  8. SQL-38 创建视图

    题目描述 针对actor表创建视图actor_name_view,只包含first_name以及last_name两列,并对这两列重新命名,first_name为first_name_v,last_n ...

  9. Day8作业及默写

    1,有如下文件,a1.txt,里面的内容为: 老男孩是最好的培训机构, 全心全意为学生服务, 只为学生未来,不为牟利. 我说的都是真的.哈哈 分别完成以下的功能: 将原文件全部读出来并打印. with ...

  10. Eclipse下SpringBoot没有自动加载application.properties文件

    Eclipse内创建SpringBoot项目,在java/main/resources文件夹下面创建application.properties配置文件,SpringApplication.run后发 ...