随笔分类 -  最小生成树

摘要:http://poj.org/problem?id=1511题意:在一个图中,求从1号节点到2-n号节点的最短距离和和从2-n节点到1节点的最短距离和;思路:因为数据太大,用spfa,且要建立双向的;代码:View Code #include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;#define max 1000010#define inf 1000000050stru 阅读全文
posted @ 2012-04-27 22:14 LT-blogs 阅读(229) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3026题意:在一个y行 x列的迷宫中,有可行走的通路空格’ ‘,不可行走的墙’#’,还有两种英文字母A和S,现在从S出发,要求用最短的路径L连接所有字母,输出这条路径L的总长度;思路:用bfs找出每两个点之间的距离,然后用prim求出最小生成树;思路是参考网上的;代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <queue>using name 阅读全文
posted @ 2012-03-16 15:03 LT-blogs 阅读(203) 评论(0) 推荐(0)