hdu5137 How Many Maos Does the Guanxi Worth(单源最短路径)
题目链接: pid=5137">点击打开链接
题目描写叙述:如今有一张关系网。网中有n个结点标号为1~n。有m个关系,每一个关系之间有一个权值。问从2~n-1中随意去掉一个结点之后,从1~n的距离中全部最小值的最大值为多少?
解题思路:多次调用Dijkstra就可以,每次标记那个结点不通就可以
代码:
#include <cstdio>
#include <queue>
#include <cstring>
#define MAXN 31
#define MAXE 1010
#define INF 1e9+7
using namespace std;
int head[MAXN];
struct Edge{
int to,cost,next;
}edge[MAXE*2];
struct node{
int ct;
int cost;
node(int _ct,int _cost):ct(_ct),cost(_cost){}
bool operator<(const node& b)const{///注意优先权队列:<代表大顶堆,>代表小顶堆
return cost>b.cost;
}
};
int tol;
void addEdge(int x,int y,int cost){
edge[tol].to=y;
edge[tol].cost=cost;
edge[tol].next=head[x];
head[x]=tol++; edge[tol].to=x;
edge[tol].cost=cost;
edge[tol].next=head[y];
head[y]=tol++;
}
int n,m;
int dis[MAXN];
bool vis[MAXN];
void bfs(int nt){
memset(vis,false,sizeof(vis));
vis[nt]=true;
for(int i=1;i<=n;++i)
dis[i]=INF;
dis[1]=0;
priority_queue<node> pq;
while(!pq.empty()) pq.pop();
pq.push(node(1,0));
while(!pq.empty()){
node tmp=pq.top();
pq.pop();
int u=tmp.ct;
if(vis[u]) continue;
vis[u]=true;
for(int i=head[u];i!=-1;i=edge[i].next){
int v=edge[i].to;
int cost=edge[i].cost;
if(!vis[v]&&dis[v]>dis[u]+cost){
dis[v]=dis[u]+cost;
pq.push(node(v,dis[v]));
}
}
}
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0)){
tol=0;
memset(head,-1,sizeof(head));
int x,y,cost;
for(int i=1;i<=m;++i){
scanf("%d%d%d",&x,&y,&cost);
addEdge(x,y,cost);
}
int ans=0;
for(int i=2;i<n;++i){
bfs(i);
ans=max(ans,dis[n]);
}
if(ans<INF)
printf("%d\n",ans);
else
printf("Inf\n");
}
return 0;
}
hdu5137 How Many Maos Does the Guanxi Worth(单源最短路径)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Linux版本分支图
- Golang 源码剖析:log 标准库
Golang 源码剖析:log 标准库 原文地址:Golang 源码剖析:log 标准库 日志 输出 2018/09/28 20:03:08 EDDYCJY Blog... 构成 [日期]<空格 ...
- 2019-03-18 使用Request POST获取CNABS网站上JSON格式的表格数据,并解析出来用pymssql写到SQL Server中
import requests import pymssql url = 'https://v1.cn-abs.com/ajax/ChartMarketHandler.ashx' headers = ...
- NOIP2018提高组省一冲奖班模测训练(三)
NOIP2018提高组省一冲奖班模测训练(三) 自己按照noip的方式考,只在最后一两分钟交了一次 第一题过了,对拍拍到尾. 第二题不会.考试时往组合计数的方向想,推公式,推了一个多小时,大脑爆炸,还 ...
- STM32 Cubemx 输出可调频率与占空比的PWM
这里就不对STM32的PWM进行讲解了,想要了解的可以百度一下,这里主要说怎么实现. 1.建立工程,我选的是STM32F103zet6芯片,选择定时器的PWM功能 2.配置时钟,我这里配的是内部时钟, ...
- 样本方差的无偏估计与(n-1)的由来
一.无偏估计 所谓总体参数估计量的无偏性指的是,基于不同的样本,使用该估计量可算出多个估计值,但它们的平均值等于被估参数的真值. 在某些场合下,无偏性的要求是有实际意义的.例如,假设在某厂商与某销售商 ...
- HDU 2155 Matrix
Matrix Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 215 ...
- COGS——T 886. [USACO 4.2] 完美的牛栏
http://www.cogs.pro/cogs/problem/problem.php?pid=886 ★★☆ 输入文件:stall4.in 输出文件:stall4.out 简单对比时间 ...
- 一个HTTP连接是包含两部分的,请求报文和响应报文这俩组合起来才是一次完整的HTTP请求,并不会单独显示请求报文或者响应报文
一个HTTP连接是包含两部分的,请求报文和响应报文这俩组合起来才是一次完整的HTTP请求,并不会单独显示请求报文或者响应报文. 2.注意看,一次HTTP请求,是包括这两部分的
- Python中常见的文件对象内建函数
文件对象内建方法列表 文件对象的方法 操作 file.close() 关闭文件 file.fileno() 返回文件的描写叙述符(file descriptor.FD,整数值) file.flush( ...