https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5091

题目大意:n个人编号从1到n,m条关系,a找b帮忙或b找a帮忙需要花费c元,当然a可以通过d找b帮忙(即a找d帮忙,d再找b帮忙)

现在1号要找n号帮忙,你需要去找1号和n号之外的人,让他不帮忙,即破坏这条关系链,如果1号最终能找n号b帮忙则输出过程中所

用的最大花费,否则输出Inf

分析:

转化为最短路问题:a到b的花费当做a点到b点的距离

破坏关系链只需在2—n-1号这n-3点中依次找每一个点,将该点到其他点和其他点到该点的距离令为INF,然后找一个1到n的最小距离,

得到n-3个距离,输出这n-3个距离中最大的距离

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std; const int N = ;
const int INF = 0x3f3f3f3f; int G[N][N], maps[N][N];
int n; void Init()
{
int i, j;
for(i = ; i <= n ; i++)
{
for(j = ; j <= n ; j++)
{
if(i == j)
G[i][j] = ;
else
G[i][j] = G[j][i] = INF;
}
}
} int Floyd(int m)
{
int i, j, k;
for(i = ; i <= n ; i++)
{
for(j = ; j <= n; j++)
{
if(i == m || j == m)
maps[i][j] = maps[j][i] = INF;//让编号为m的人不帮,来破坏该条关系链
else
maps[i][j] = maps[j][i] = G[i][j];
}
}
for(k = ; k <= n ; k++)
{
for(i = ; i <= n ; i++)
{
for(j = ; j <= n ; j++)
{
if(maps[i][j] > maps[i][k] + maps[k][j])
maps[i][j] = maps[i][k] + maps[k][j];
}
}
}
return maps[][n];
} int main()
{
int m, i, a, b, c;
while(scanf("%d%d", &n, &m), m + n)
{
Init();
while(m--)
{
scanf("%d%d%d", &a, &b, &c);
G[b][a] = G[a][b] = c;
}
int ans = ;
for(i = ; i <= n - ; i++)
ans = max(ans, Floyd(i));
if(ans == INF)
printf("Inf\n");
else
printf("%d\n", ans);
}
return ;
}

UVALive 7079 - How Many Maos Does the Guanxi Worth(最短路Floyd)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  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 ...

  6. 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 ...

  7. (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 ...

  8. 杭电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 ...

  9. 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 ...

随机推荐

  1. [转]JAVA中Action层, Service层 ,modle层 和 Dao层的功能区分

    首先这是现在最基本的分层方式,结合了SSH架构.modle层就是对应的数据库表的实体类.Dao层是使用了Hibernate连接数据库.操作数据库(增删改查).Service层:引用对应的Dao数据库操 ...

  2. HDU 1527 (Wythoff 博弈) 取石子游戏

    对于Wythoff博弈中的两个数列,An和Bn有这样的关系: An + n = Bn, An = floor(φ * n) 所以我们可以根据a b的差值来计算一个新的a出来看看这两个值是否相等. 想等 ...

  3. Tarjan算法应用 (割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)问题)(转载)

    Tarjan算法应用 (割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)问题)(转载) 转载自:http://hi.baidu.com/lydrainbowcat/blog/item/2 ...

  4. I.MX6 uSDHC SD card register

    /**************************************************************************** * I.MX6 uSDHC SD card ...

  5. 每天一个Linux命令(1): find

    1 find 命令是用来查找制定目录下符合条件的文件执行相应的动作(print exec等) find [path...] [expression] path:find命令所查找的目录路径.例如用.来 ...

  6. js二级下拉被flash档住的解决办法

    在<object></object>及以内的代码加入到<script>标签对内 <script language="javascript" ...

  7. jQuery.validate API

  8. 计算机网络——TCP/IP协议族详解

    一.OSI七层协议体系结构域TCP/IP四层体系结构对比 ISO/OSI模型,即开放式通信系统互联参考模型(Open System Interconnection Reference Model),是 ...

  9. for-in遍历json数据

    1.for遍历json数据 ','fun':'前端开发'} for(var attr in json){ alert(json[attr]) //遍历json属性的数据 alert(json['nam ...

  10. python numpy sum函数用法

    numpy.sum numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)[source] Sum of array element ...