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. jquery仿天猫商城左侧导航菜单

    之前看到有博友写了一个仿天猫商城左侧导航菜单,可惜不提供免费下载,也没有代码.以前自己也写过类似的效果,只是都是一小块一小块的,现在重新拼凑.我将一步一步的实现拼凑过程,希望对你有所帮助. Demo在 ...

  2. 51nod1379 索函数

    果断打表找规律.然后看得出来是2^k-1之后又不知道怎么求出k有什么卵用... http://blog.csdn.net/guhaiteng/article/details/52094210 %%%% ...

  3. hdu 4614 pieces 状态DP

    题意:给你一个长度小于等于16的字符串,每次可以删除一个回文传,问你最少删除干净的字数. 状态+dp dp[i] = min(dp[i],dp[j]+dp[j^i]);(j是i的字串): 连接:htt ...

  4. 14.Object-C--浅谈Foundation框架字符串NSString 与NSMutableString

    OC的字符串时经常使用到的,今天我对于OC字符串做一个简单的总结,如果有错误之处,麻烦留言指正.感谢! NSString是一个不可变长度的字符串对象.表示它初始化以后,你不能改变该变量所分配的内存中的 ...

  5. Spring无配置使用properties文件

    利用@PropertySource注解加载 @Configuration @ComponentScan(basePackages="*") @PropertySource({&qu ...

  6. (六) 6.2 Neurons Networks Backpropagation Algorithm

    今天得主题是BP算法.大规模的神经网络可以使用batch gradient descent算法求解,也可以使用 stochastic gradient descent 算法,求解的关键问题在于求得每层 ...

  7. 【Python】Python重新学习

    <python基础教程(第二版)> http://www.cnblogs.com/fnng/category/454439.html 分片(后面取的是前一位) eg: >>&g ...

  8. js sleep效果

    js sleep效果 s = setInterval(function(){ //需要执行的函数 alert("我延迟了2秒弹出"); },2000); 并不是每2秒执行一次,而是 ...

  9. mysql 概念和逻辑架构

    1.MySQL整体逻辑架构 mysql 数据库的逻辑架构如下图: 第一层,即最上一层,所包含的服务并不是MySQL所独有的技术.它们都是服务于C/S程序或者是这些程序所需要的 :连接处理,身份验证,安 ...

  10. linux 安装SVN

    1.环境centos6.4 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svnserve -d -r /www/sv ...