HDU5137-最短路最大化-How Many Maos Does the Guanxi Worth
来源:互联网 发布:数控车床编程自学视频 编辑:程序博客网 时间:2024/06/13 17:01
https://vjudge.net/contest/174794#problem/K
一个图 m个点 n个边,
可以删除一个点(与之连接的边也删除),令其之后的最短路最大,问你最短路长度是多少。 如果删除一个就不能连通了那就输出Inf(第一个字母大写的,,因为这个wa了6次。。)
开始的想法是 枚举删除的点,求最短路,因为想另其最大,我们就求取最大的就行,如果最大都是 dis的初始值,则说明不能连通
( 开始想了一个求一个 最短路和最长路,然后如果相等则说明不通,否则输出最长路,但是很可能输出一个点之后也不到最长路,并且 最短==最长 这个判断是否存在也错了)
这种情况,是要删除这个点,另其为inf的。而不是删除其他保留下面那个路
因为本来就是让这层关系网断了最好。(题意。。。)
#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <algorithm>#include <map>#include <cstring>#include <set>#include <queue>using namespace std;const int inf=0x3f3f3f3f;const int maxn=2000;struct Node{ int v; int cost; Node(int _a,int _b){v=_a;cost=_b;} Node(){};};bool vis[maxn];vector<Node>G[maxn];int m;int n;int dis[maxn];int spfa(int s){ memset(vis,false,sizeof(vis)); for(int i=1;i<=m;i++) dis[i]=inf; queue<int>q; q.push(1); dis[1]=0; vis[1]=true; while(!q.empty()){ int u=q.front(); q.pop(); vis[u]=false; for(int i=0;i<G[u].size();i++){ int v=G[u][i].v; if(v==s) continue; if(dis[v]>dis[u]+G[u][i].cost){ dis[v]=dis[u]+G[u][i].cost; if(!vis[v]){ q.push(v); vis[v]=true; } } } }return dis[m];}int main(){ int a,b,c; while(~scanf("%d%d",&m,&n)){ if(m==0&&n==0) break; for(int i=0;i<maxn;i++) G[i].clear(); for(int i=0;i<n;i++){ scanf("%d%d%d",&a,&b,&c); G[a].push_back(Node(b,c)); G[b].push_back(Node(a,c)); } int maxx=-inf; for(int i=2;i<m;i++){ int vis=i; int s=spfa(vis); //cout<<s<<"!!"<<endl; if(s!=0) maxx=max(s,maxx); } if(maxx==inf) puts("Inf"); else printf("%d\n",maxx); //cout<<maxx<<endl; } return 0;}
阅读全文
0 0
- 【最短路】HDU5137 How Many Maos Does the Guanxi Worth
- HDU5137-最短路最大化-How Many Maos Does the Guanxi Worth
- HDU5137 How Many Maos Does the Guanxi Worth(最短路,spfa)
- hdu5137 How Many Maos Does the Guanxi Worth
- HDU5137 How Many Maos Does the Guanxi Worth
- HDU5137 How Many Maos Does the Guanxi Worth (14广州现场赛K题 )--最短路问题
- [ACM] HDU 5137 How Many Maos Does the Guanxi Worth(去掉一个点使得最短路最大化)
- hdu1537How Many Maos Does the Guanxi Worth【最短路&&最短路径最大化】~
- hdoj5137How Many Maos Does the Guanxi Worth【最短路】
- hdu5137How Many Maos Does the Guanxi Worth【最短路最大值】
- HDU5137How Many Maos Does the Guanxi Worth(最短路)
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- hdoj 5137 How Many Maos Does the Guanxi Worth【最短路】
- Ubuntu
- Cleaning Shifts
- 洛谷P3375 【模板】KMP字符串匹配
- 如何连接阿里云Linux实例
- Linux环境下安装JDk
- HDU5137-最短路最大化-How Many Maos Does the Guanxi Worth
- java杂记1
- angular2——前后端交互
- Jsoup学习
- KMP题目分析与总结
- 计蒜客NOIP提高组模拟Day2,Pro1蒜头君的兔子
- 14 在ZStack里的网络广播传输
- javase复习(四)--Arrays.asList()方法的使用
- LeetCode