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 ...
随机推荐
- 使用 NumPy 和 Matplotlib 绘制函数图
Numpy是用python进行科学计算的基本程序包. 它主要包含以下功能: ♦强大的n维数组对象 ♦复杂(广播)函数工具 ♦用于集成c/c++和Fortran代码-有用的线性代数 ♦傅里叶变换和随机数 ...
- laravel中的登录页面逻辑
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades ...
- linux用户管理 查看用户信息
LINUX系统中用户登录查看命令 W命令 [root@ssgao1987 ~]# w 04:57:01 up 11:50, 2 users, load average: 0.00, 0.00, 0 ...
- win10与centos7的双系统U盘安装(一:制作u盘启动盘)
博主近来在学习linux系统,当然学习第一步自然是安装系统了,博主选择的是centos7,博主自己的电脑是联想的,系统是win10专业版,在历经数次失败后,博主成功使用u盘安装了win10和cento ...
- Linux运维工程师必学必备的8项IT技能
如果你在学习Linux,那么强烈推荐你选择RHEL和Centos作为学习的Linux发行版本,在公司及企业当中他们是使用最多的,毕竟学习除了本身是爱好,其次也是为了就业.Centos是RHEL的克隆版 ...
- nginx+tomcat集群
参考: 简单:http://blog.csdn.net/wang379275614/article/details/47778201 详细:http://www.jb51.net/article/77 ...
- VirtualBox安装CentOS7的网络配置
VirtualBox安装CentOS7的网络配置 这几天在本机VirtualBox安装CentOS时遇到了网络的坑... VirtualBox的下载地址:https://www.virtualbox. ...
- uitableView group模式下的间距问题
我么在使用group模式定义tableview的时候,系统默认是会有head和foot的间距的,来区分我们不同的group:在具体使用的时候又时候我们不需要这个间距.我们可以重新赋值这些间距来达到我们 ...
- eclipse server和tomcat的区别,将server的部署目录改到自己安装的tomcat中及如何设置tomcat用户
转:http://www.cnblogs.com/Yogurshine/archive/2013/06/05/3118525.html 一.发现问题(如果不把项目部署到tomcat的webapp目录下 ...
- 3.4 C++名字隐藏
参数:http://www.weixueyuan.net/view/6361.html 总结: 如果派生类中新增一个成员变量,该成员变量与基类中的成员变量同名,则新增的成员变量就会遮蔽从基类中继承过来 ...