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. BZOJ 1123 BLO

    tarjan求割点计算答案.注意不是每一棵子树都算答案.开个变量记一下. #include<iostream> #include<cstdio> #include<cst ...

  2. js屏弊错误

    <SCRIPT language=javascript> <!-- window.onerror=function(){return true;} // --> </SC ...

  3. yaf框架流程二

    这篇讲讲yaf的配置文件,首先上我的配置代码: [common] ;必选配置 ;application.directory String 应用的绝对目录路径 ;可选配置 ;名称 值类型 默认值 说明 ...

  4. xsheell的下载安装初级使用

    1)关于Xshell 网上更多的资料里提到的SSH客户端是putty,因为简单.开源.免费.但是也正是由于功能过于简单,所以在这里推荐大家使用Xshell. Xshell最初并不能免费使用,而且也没有 ...

  5. 计算机网络——超文本传送协议HTTP

    一.简述 每个万维网网点都有一个服务器进程,它不断地监听TCP的端口80,以便发现是否有浏览器向它发出连接建立请求.一旦监听到连接建立请求并建立了TCP连接之后,浏览器就向万维网服务器发出浏览某个页面 ...

  6. Android 着色器 Tint 研究

    Tint 这个东西 主要用来减少apk体积的,比如说我现在有一个textview,他的背景图 有两种,一种是当获得焦点时显示的a图,另一种是 失去焦点时显示的b图. 相信大家开发的时候 这种需求做过很 ...

  7. 【Mongo】MongoVUE的使用

    我一直是在终端操作的mongo,各种update set remove insert,后来查了下有个叫mongoVUE的客户端,界面化比较方便操作吧~ 网上搜了下,说MongoVUE已经n年没有更新了 ...

  8. Drupal 7.23:函数module_invoke_all()注释

    /** * Invokes a hook in all enabled modules that implement it. * * All arguments are passed by value ...

  9. HTTP协议的状态码

    对于Web编程人员来说,熟悉了解HTTP协议的状态码是很有必要的,很多时侯可能根据HTTP协议的状态码很快就能定位到错误信息!今天整理了一下所有HTTP状态码. HTTP状态码(HTTP Status ...

  10. jQuery对select标签的常用操作

    1.获取当前选中项的value. $("#selector").val(); 2.获取当前选中项的text. $("#selector").find(" ...