随笔分类 -  图论

OJ上图论相关题,图论学习笔记
摘要:题目:http://poj.org/problem?id=2253题目大意:找到从点1到点2的某一条路中最长边,使最长的这条边尽量短算法:Kruscal思路:搜了题解……找最小生成树,加入某条边后点1和点2联通了,那么这条边就是所求边提交状况:OLE 1次, WA n次, AC 1次总结:从昨天上午纠结到今天中午……就是懒得建图……并查集也有问题,先是细节,再是路径压缩不对。我WA了一上午的题啊,同学过来不到两分钟就发现错误了……我掩面逃走……AC code :View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 阅读全文
posted @ 2011-07-23 13:49 cloehui 阅读(187) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2387题目大意:找出从1到n的最短路算法:Dijkstra思路:很裸的Dijkstra,主要是想练习用邻接表建图提交情况:WA 3次, RE 3次, AC 1次总结:很裸的Dijkstra,主要是想练习用邻接表建图。AC的很纠结,先是懒没有判重,后来发现是无向图,改完就开始RE,开了2100的边集,一直RE,开到20100才AC。题目明明写的T <= 2000 啊,为什么就不够呢……AC code:View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 阅读全文
posted @ 2011-07-22 11:11 cloehui 阅读(233) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=3259题目大意:有F个fields,N条正常的路径,W个虫洞,走正常路径耗时,走虫洞减时。要从原点走一条回路,满足再回到原点时所用时间和小于0思路:Bellman-Ford判断从源点可达的负权回路算法:Bellman-Ford提交情况:WA n次, AC 1次总结:正常路径是双向的,虫洞是单向的。所以最多一共有(2 * M + W)条路,先开始数据开小了。AC code :View Code 1 #include <cstdio> 2 3 #include <cstring> 4 5 #include < 阅读全文
posted @ 2011-07-20 16:30 cloehui 阅读(284) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=1861题目大意:要用最短的电缆把所有的电脑都连接起来。算法:Kruscal+并查集思路:常规Kruscal+并查集。先开始没注意到是SPJ,看样例输出一个环很是疑惑,纠结了半天,看了discuss,才知道是样例的问题……不用管样例,常规做就好提交情况:1次ACAC code:View Code 1 #include <cstdio> 2 3 #include <cstdlib> 4 5 #include <cstring> 6 7 #include <algorithm> 8 9 usi 阅读全文
posted @ 2011-07-20 16:29 cloehui 阅读(296) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2395题目大意:找到连接所有农场的最小生成树,并找到其中最长的一条路。算法:Kruskal+并查集提交情况:1次AC思路:很裸的Kruskal+并查集,连边数都给出来了。建立边集,常规Kruskal+并查集,记录当前最小生成树中最大边。AC codeView Code 1 #include<stdio.h> 2 3 #include<stdlib.h> 4 5 #include<string.h> 6 7 #include<algorithm> 8 9 using namespace s 阅读全文
posted @ 2011-07-20 16:27 cloehui 阅读(277) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=1258题目大意:多组测试用例,找出连接所有农场的最短路径。算法:最小生成树 + 并查集。提交情况:1次WA,1次RE,1次AC。总结:没注意到多组用例;边集一定要开够。思路:建立无向图,用上三角矩阵表示,并查集 + Kruskal建最小生成树,记录总长度。AC code:View Code 1 #include <stdio.h> 2 3 #include <stdlib.h> 4 5 #include <string.h> 6 7 #include <algorithm> 8 9 us 阅读全文
posted @ 2011-07-20 16:25 cloehui 阅读(267) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2485题目大意:输入各城镇之间的距离,求最小生成树中最长的边。算法:最小生成树。提交情况:3次RE,1次AC总结:边集一定要开大。思路:建立无向图,用上三角矩阵表示,并查集 + Kruskal建最小生成树,记录树中最长边。AC code:View Code 1 #include <stdio.h> 2 3 #include <stdlib.h> 4 5 #include <string.h> 6 7 #include <algorithm> 8 9 using namespace std 阅读全文
posted @ 2011-07-20 16:23 cloehui 阅读(225) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1241题目大意:简单的dfs~ 搜索地图,每找到一个油田,就搜索八个方向,将连着的油田标记为同一个。算法:dfsAC code:View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #define MAXN (100 + 10) 5 char map[MAXN][MAXN]; 6 int oil; 7 int m, n; 8 9 int dx[8] = {-1,-1,- 阅读全文
posted @ 2011-07-20 13:12 cloehui 阅读(298) 评论(0) 推荐(0)