UVALive 7079 - How Many Maos Does the Guanxi Worth(最短路Floyd)
题目大意: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)的更多相关文章
- 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 最短路 dijkstra
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 ...
- 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 ...
- 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 ...
- (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 ...
- 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 ...
随机推荐
- Qt之等待提示框(QTimer)
简述 上节讲述了关于QPropertyAnimation实现等待提示框的显示,本节我们使用另外一种方案来实现-使用定时器QTimer,通过设置超时时间定时更新图标达到旋转效果. 简述 效果 资源 源码 ...
- office编程必不可少 [转]
1. 微软官方实例: 段落.表格.图表 HOW TO:利用 Visual C# .NET 使 Word 自动新建文档 2. 学习资源 (1)Word in the Office 基础知识,必读,下面的 ...
- Using unique option prefix myisam-recover instead of myisam-recover-option
[转载]关于mysql error.log报"Using unique option prefix myisam-recover instead of myisam-recover-opti ...
- 菜鸟学习笔记2,$(document).ready()使用讨论
$(document).ready()使用讨论 $(document).ready() 一.先为说说 $(document).ready() 的功能: 1. JQuery API对 $(docume ...
- 一行JS代码,解决DedeCMS TAG标签错误输入符号问题
在维护内容的时候, Tag标签输入经常要来回切换输入法, 只能通过','号分隔. 中文用户, 输入法出来的经常是全角的, 经常弄错, 增加了检查的工作量, 现在只要一句JS代码, 就自动替换所有 ...
- NBUT 1122 Shameimaru's Candid Camera(水)
题意: 给n*m个格子,初始时每个格子中有个数值为0,部分格子中含有炸弹,每个炸弹爆炸可以将周围的8个非炸弹格子中的数值加1,求全部炸弹炸完后那些非0且非炸弹格子中的数是多少. 思路: 另开一个矩阵, ...
- 本地Git环境配置
在Git Bash下获取源码时,提示permission denied publickey. 原因是本地帐号配置不正确,解决办法 生成SSH文件 1,进入Git Bash 2, 输入下面文字 ssh ...
- tilecache2.11在windows apache2.22安装部署
tilecache2.11在windows apache2.22安装部署 蔡建良 2013-09-03 一.安装环境 操作系统: Windows7 32位 Apache2.22 Python2.5 m ...
- 阻塞、非阻塞的概念和select函数的阻塞功能
其它文档: http://www.cnitblog.com/zouzheng/archive/2010/11/25/71711.html (1)阻塞block 所谓阻塞方式block,顾名思义 ...
- size_type、size_t、differentce_type以及ptrdiff_t
目录(?)[-] size_type size_t different_type ptrdiff_t size_t是unsigned类型,用于指明数组长度或下标,它必须是一个正数,std::siz ...