UVa 11463 - Commandos

来源:互联网 发布:剑雨江湖进阶数据仙器 编辑:程序博客网 时间:2024/05/20 17:07

题目:有一个敢死队,要摧毁一群建筑,他们从一个特定的建筑出发,最后到一个特定的建筑集合;

            现在给你各个建筑之间的连接路线,在建筑中穿梭需要1个单位时间,问集合的最早时间。

分析:图论,最短路径。直接计算起点s和终点e到那个其他所有点的最短路径;

            取min(dist(s,k)+ dist(k,e))即可(0≤k<n)。

说明:第650题目╮(╯▽╰)╭。

#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;int path[101][101];int main(){int T,n,m,u,v,b,e;while (~scanf("%d",&T))for (int t = 1; t <= T; ++ t) {scanf("%d%d",&n,&m);for (int i = 0; i < n; ++ i) {for (int j = 0; j < n; ++ j)path[i][j] = 101;path[i][i] = 0;}for (int i = 0; i < m; ++ i) {scanf("%d%d",&u,&v);path[u][v] = path[v][u] = 1;}//floydfor (int k = 0; k < n; ++ k)for (int i = 0; i < n; ++ i)for (int j = 0; j < n; ++ j)if (path[i][j] > path[i][k]+path[k][j])path[i][j] = path[i][k]+path[k][j];scanf("%d%d",&b,&e);int max = 0;for (int k = 0; k < n; ++ k)if (max < path[b][k]+path[k][e])max = path[b][k]+path[k][e];printf("Case %d: %d\n",t,max);}    return 0;}


0 0