hdu5173 How Many Maos Does the Guanxi Worth
#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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- (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 ...
- 杭电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 ...
- 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 ...
随机推荐
- .NetCore发布到Centos docker
将.netcore mvc项目发布到centos7的docker中.环境 vmware14+Centos7+docker-ce 1.使用vs将.netcoremvc项目发布到本地,修改发布后的目录 名 ...
- css中的position属性值的探究
css的position属性指定了元素的定位类型,然后通过top,botton,left,right来具体定位. 在具体定位之前必须使用position属性,否则所有的具体定位属性都无法生效. pos ...
- Unity3D在C#编程中的一些命名空间的引用及说明
System包含用于定义常用值和引用数据类型.事件和事件处理程序.接口.属性和处理异常的基础类和基类.其他类提供支持下列操作的服务:数据类型转换,方法参数操作,数学计算,远程和本地程序调用,应用程序环 ...
- unity鼠标滚轮控制摄像机视野的缩放和按住鼠标控制摄像机移动
//摄像机前进后退的速率 private float view_value=20f; private float maximum = 100; private float minmum = 30; / ...
- 【资料搜集】DirectX学习
[网站推荐:]GameRes游资网-游戏开发者门户 http://www.gameres.com/ [基础知识:] <游戏编程>第一部 基础篇 - GameRes.com http://d ...
- [Leetcode 881]船救人 Boats to Save People 贪心
[题目] The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each b ...
- 2.18 C++类与static关键字
参考:http://www.weixueyuan.net/view/6349.html 总结: 类中的成员变量或成员函数一旦与static关键字相结合,则该成员变量或成员函数就是属于类的,而不是再是属 ...
- SharePoint Framework 构建你的第一个web部件(一)
博客地址:http://blog.csdn.net/FoxDave SharePoint客户端web部件是出现在SharePoint页面的控件,但却是在浏览器本地运行的.他们是SharePoint ...
- django面试二
33. django的缓存能使用redis吗?如果可以的话,如何配置? #1.安装 pip install django-redis#2.在stting中配置CACHES,可以设置多个缓存,根据名字使 ...
- python selenium爬取QQ空间方法
from selenium import webdriver import time # 打开浏览器 dr = webdriver.Chrome() # 打开某个网址 dr.get('https:// ...