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 ...
随机推荐
- 七、利用frp 穿透到内网的http/https网站,实现对外开放
有域名的话使用域名,没有域名的话使用IP注意80端口是否被已经安装使用的nginx占用,若被占用,可以换成其他端口,比如8080,,或者利用nginx的反向代理实现frp服务端与nginx共用80端口 ...
- nignx 502错误不能使用/的路径方式 即pathinfo
在server中加入 include enable-php-pathinfo.conf; 引入nginx.conf下的这个文件即可. 如果是tp框架,主要隐藏index.php的入口文件,再加入下面这 ...
- datalist标签 输入框候选
H5的datalist标签,可以给input输入框提供下拉选择列表,或输入提示功能. 写如下的datalist标签 <datalist id="car"> <op ...
- 2015 Multi-University Training Contest 7 hdu 5379 Mahjong tree
Mahjong tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- Accessibility辅助控制类
熟悉Android开发的都知道辅助功能服务 Accessibility service.他的作用有非常多.360豌豆荚等应用市场的非root自己主动安装.微信抢红包插件.盲人辅助程序等等功能都是靠它实 ...
- NYOJ 915 +-字符串【贪心】
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描写叙述 Shiva得到了两个仅仅有加号和减号的字符串,字串长度同样.Shiva一次能够把一个加号和它相邻的减号交换 ...
- C++ Primer Plus的若干收获--(九)
这篇博文我接着上一篇来写,相同讲一些关于类的一些基础知识. 本篇将会继续使用上篇的股票类STock,这里给出接口 ifndef STOCKOO_H_ #define STOCKOO_H_ #inclu ...
- [luogu P2123] 皇后游戏 解题报告(贪心)
题目链接:https://www.luogu.org/problemnew/show/P2123 题目大意: 给定a数组和b数组,要求最小化c数组中的最大值 题解: 考虑微扰法,推一波式子先 设$x= ...
- threejs 入门教程1
最近在看threejs开发指南,总结一下制作最基础的3d场景的8步: 1. 设置场景大小 2. 创建WebGl渲染器 3. 指定根节点元素 4. 初始化场景 5. 添加相机到场景 6. 创建物体到场景 ...
- C语言学习小记
2013年1月31日 今天试着编程为报文去头去尾. #include #include #define MAX_LENTH 1024 int main() { char *path = &quo ...