zoukankan      html  css  js  c++  java
  • UVa 11463

    主题:有一个敢死队,要销毁的建筑群,他们从一个特定建筑物离开,最后到一组特定的建筑物的。

                现在,各个建筑物之间进行连接的路由,班车需要在建筑物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;
    		}
    		//floyd
    		for (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
    ",t,max);
    	}
        return 0;
    }
    


  • 相关阅读:
    数位dp模板
    HDU
    hdu 2586 How far away ? ( 离线 LCA , tarjan )
    POJ 1655 Balancing Act( 树的重心 )
    HDU 2196 Computer( 树上节点的最远距离 )
    HDU 5266 pog loves szh III ( LCA + SegTree||RMQ )
    HDU 5265 pog loves szh II
    2015区域赛起航
    2015GDCPC广东省赛总结
    SGU 521 North-East ( 二维LIS 线段树优化 )
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5039562.html
Copyright © 2011-2022 走看看