hdu5137 How Many Maos Does the Guanxi Worth
来源:互联网 发布:棋牌游戏源码作弊 编辑:程序博客网 时间:2024/06/01 15:32
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1 << 27;
const int N = 1005;
int path[N][N], path0[N][N];
int m, n;
int Min(int a, int b)
{
return a > b ? b : a;
}
int floyd(int k)
{
int i, j;
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
{
if(i == k || j == k) path[i][j] = INF;
else path[i][j] = path0[i][j];
}
for(k = 1; k <= n; k ++)
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
path[i][j] = Min(path[i][k] + path[k][j], path[i][j]);
return path[1][n];
}
int main()
{
// freopen("in.txt", "r", stdin);
int i, j, A, B, C, st, ed, maxx, num;
while(~scanf("%d%d", &n, &m) && (n || m))
{
maxx = 0;
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
{
if(i == j) path0[i][j] = path0[i][j] = 0;
else path0[i][j] = path0[j][i] = INF;
}
for(i = 1; i <= m; i ++)
{
scanf("%d%d%d", &A, &B, &C);
if(path0[A][B] > C) path0[A][B] = path0[B][A] = C;
}
for(i = 2; i < n; i ++)
{
num = floyd(i);
if(maxx < num) maxx = num;
}
if(maxx == INF) printf("Inf\n");
else printf("%d\n", maxx);
}
return 0;
#include <string.h>
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1 << 27;
const int N = 1005;
int path[N][N], path0[N][N];
int m, n;
int Min(int a, int b)
{
return a > b ? b : a;
}
int floyd(int k)
{
int i, j;
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
{
if(i == k || j == k) path[i][j] = INF;
else path[i][j] = path0[i][j];
}
for(k = 1; k <= n; k ++)
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
path[i][j] = Min(path[i][k] + path[k][j], path[i][j]);
return path[1][n];
}
int main()
{
// freopen("in.txt", "r", stdin);
int i, j, A, B, C, st, ed, maxx, num;
while(~scanf("%d%d", &n, &m) && (n || m))
{
maxx = 0;
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
{
if(i == j) path0[i][j] = path0[i][j] = 0;
else path0[i][j] = path0[j][i] = INF;
}
for(i = 1; i <= m; i ++)
{
scanf("%d%d%d", &A, &B, &C);
if(path0[A][B] > C) path0[A][B] = path0[B][A] = C;
}
for(i = 2; i < n; i ++)
{
num = floyd(i);
if(maxx < num) maxx = num;
}
if(maxx == INF) printf("Inf\n");
else printf("%d\n", maxx);
}
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
- 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
- hdu5137 How Many Maos Does the Guanxi Worth(单源最短路径)
- hdu5137 How Many Maos Does the Guanxi Worth(ACM/ICPC 西安区域赛现场赛)
- 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 (14广州现场赛K题 )--最短路问题
- HDOJ5317 How Many Maos Does the Guanxi Worth(floyd)
- HDOJ--5137--How Many Maos Does the Guanxi Worth
- HDUOJ_5137(dijkstra)(How Many Maos Does the Guanxi Worth)
- 杭电5137How Many Maos Does the Guanxi Worth
- LocalBroadcastManager 的问题
- 线程同步与互斥
- Spring3系列6-Spring 表达式语言(Spring EL)
- ios宏的使用和技巧
- 莫队bzoj1878
- hdu5137 How Many Maos Does the Guanxi Worth
- JS转换HTML转义符
- swift5分钟语法速记
- 5-27 冒泡法排序
- 本来连学计算机的都不是,怎么却读了计算机研究生
- 网站访问慢的案例
- java-迭代删除
- 关于解决Server Tomcat v7.0 Server at localhost failed to
- 写的数据结构1对多再对多的形式结构