
图论的各种姿势
文章平均质量分 71
BraketBN
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【BZOJ1001】[BeiJing2006]狼抓兔子【最小割】【最短路】【对偶图】
最小割等于对偶图的最短路。 #include #include #include #include #include using namespace std; typedef pair pii; const int maxd = 1005, maxn = 2000005, maxm = 3000005, inf = 0x3f3f3f3f; int n, m, head[原创 2016-03-01 16:11:37 · 604 阅读 · 0 评论 -
【Codevs1380】没有上司的舞会【树上最大独立集】【TreeDP】
【题目链接】 复习一下TreeDP。 1A。 /* Pigonometry */ #include #include using namespace std; const int maxn = 6005; int n, dp[maxn][2], w[maxn], head[maxn], cnt; struct _edge { int v, next; } g[maxn <<原创 2016-04-15 16:27:41 · 445 阅读 · 0 评论 -
【POJ3659】Cell Phone Network【树上最小点支配】【TreeDP】
【题目链接】 再写一发。 /* Pigonometry */ #include #include using namespace std; const int maxn = 10005, inf = 0x3f3f3f3f; int n, dp[maxn][3], head[maxn], cnt; struct _edge { int v, next; } g[maxn <原创 2016-04-15 17:32:48 · 360 阅读 · 0 评论 -
【BZOJ1083】[SCOI2005]繁忙的都市【最小瓶颈生成树】
【题目链接】 最小瓶颈生成树 = 最小生成树 水过。 /* Footprints In The Blood Soaked Snow */ #include #include using namespace std; const int maxn = 305, maxm = 50005; int n, m, fa[maxn]; struct _edge { int u, v,原创 2016-03-28 18:11:21 · 457 阅读 · 0 评论 -
【BZOJ1977】[BeiJing2010组队]次小生成树 Tree【次小生成树】【LCA】
【题目链接】 次小生成树。。 思路比较简单,先求出最小生成树,然后枚举每条不在最小生成树上的边(u, v),求u和v路径上的最大边权和次大边权。 如果最大边权和(u, v)的边权相等,那么减去次大边的边权,加上(u, v)的边权,更新答案。 如果最大边权比(u, v)的边权要小,那么减去最大边的边权,加上(u, v)的边权,更新答案。 调了几个小时= =,注意要开LL,而且i原创 2016-04-09 15:38:50 · 627 阅读 · 0 评论 -
【BZOJ3590】[Snoi2013]Quare【双连通分量】【状压DP】【神题】
【题目链接】 orz凯爷,见【Lethelody的题解】 首先一个双连通图可以拆为一个小双连通图和一条链。 设c[s][u][v]表示一条链的集合状态为s,链的端点分别为u和v的最短路径。 设h[s][u][0/1]表示集合状态为s,不在集合s内的点u与另一个在集合s中的点的最短路径/次短路径。 设f[s]表示集合状态为s,且s双联通的最小权值。 c可以递推转移。h原创 2016-04-07 23:19:09 · 1336 阅读 · 0 评论 -
【POJ1655】Balancing Act【树的重心】
题意: 求树的重心。 做点分治前先做的一个题。 #include #include using namespace std; const int maxn = 20005, inf = 0x3f3f3f3f; int n, head[maxn], cnt, size[maxn], id, ans; struct _edge { int v, next; } g[原创 2016-02-29 20:17:04 · 424 阅读 · 0 评论 -
【SPOJ-PT07Z】Longest path in a tree【DFS/BFS】【树的直径】
题意: 求树的直径。 先从任意一点DFS,找到深度最大的点,这个点一定是树的直径的一个端点(可以反证法证明),然后从该点DFS找到另一个端点。 #include #include using namespace std; const int maxn = 10005; int n, head[maxn], cnt, depth[maxn]; struct _edg原创 2016-02-25 18:29:55 · 943 阅读 · 0 评论 -
【BZOJ2718】[Violet 4]毕业旅行【最长反链】【传递闭包】
【题目链接】 同【BZOJ1143题解】 注意数据范围大了点... /* Pigonometry */ #include #include using namespace std; const int maxn = 505, maxm = 20005; int n, m, head[maxn], cnt, from[maxn], vis[maxn], clo; bool原创 2016-04-05 17:56:27 · 545 阅读 · 0 评论 -
【BZOJ1143】[CTSC2008]祭祀river【最长反链】【传递闭包】
【题目链接】 先用Floyd跑个传递闭包,然后建图。 最长反链长度 = 最小链覆盖数。 /* Pigonometry */ #include #include using namespace std; const int maxn = 205, maxm = 10005; int n, m, head[maxn], cnt, from[maxn], vis[maxn], c原创 2016-04-05 17:29:08 · 638 阅读 · 0 评论 -
【UVa10054】The Necklace【欧拉回路】
题意: 有n个珠子,每个珠子两端分别有两个颜色,问是否可以把这些珠子串成一个项链,使得相邻珠子的相邻两端的颜色相同。如果可以,输出任意一个方案。 不要对珠子建图,把颜色当成点,然后一个珠子上的两个颜色连无向边,跑欧拉回路就行啦。 #include #include using namespace std; const int maxn = 55; int n, m,原创 2016-02-27 08:58:21 · 664 阅读 · 0 评论 -
【BZOJ3632】外太空旅行【随机化】【最大团】
【题目链接】 目测是个最大团问题,那么直接随机化... /* Pigonometry */ #include #include #include using namespace std; const int maxn = 55; int n, ans, g[maxn][maxn], ord[maxn], vis[maxn], clo; inline int calc() {原创 2016-04-04 12:04:38 · 721 阅读 · 0 评论 -
【Uva11324】The Largest Clique【SCC】【最长路】【有向图最大团】
【题目链接】 题意:有向图最大团,即选出一些点,使得任意两点u, v,要么u可以到v,要么v可以到u,也可以互达。 先SCC缩点变为DAG,然后求最长路。 /* Pigonometry */ #include #include using namespace std; const int maxn = 1005, maxm = 50005, maxs = 10000, maxq原创 2016-04-02 11:40:44 · 494 阅读 · 0 评论 -
【SPOJ-SCPC11H】Dolls【最小路径覆盖】
题意: 有一些箱子,已知长宽高(不能旋转),一个较大的箱子中最多可以放入一个较小的箱子(小箱子里有可能也有箱子),问最外层最少有多少箱子。 相当于有一些点(x, y, z),若两个点i和j满足xi 由最小路径覆盖 = n - 二分图最大匹配,写个hungary即可。 #include const int maxn = 505, maxm = maxn * maxn原创 2016-02-23 22:10:37 · 625 阅读 · 0 评论 -
【BZOJ1016】[JSOI2008]最小生成树计数【最小生成树】【搜索】
【题目链接】 参考了【hzwer的题解】orz 要利用最小生成树的性质:对于所有的最小生成树,边权相等的边出现次数都相同。 /* Footprints In The Blood Soaked Snow */ #include #include using namespace std; const int maxn = 105, maxm = 1005, p = 31011; i原创 2016-03-31 16:40:39 · 395 阅读 · 0 评论 -
【BZOJ1098】[POI2007]办公楼biu【BFS/DFS】【链表优化】【补图】
求补图的联通块个数... 发现链表原来还可以这么玩... 听说DFS会超时。 /* Footprints In The Blood Soaked Snow */ #include #include using namespace std; const int maxn = 100005, maxm = 2000005, maxq = maxn; int n,原创 2016-03-04 20:51:16 · 1098 阅读 · 0 评论 -
【BZOJ1997】[Hnoi2010]Planar【平面图判定】【2-SAT】
判断存在一条Hamilton回路的图是否是平面图。 和POJ3207几乎一样,只要把 判断相交的条件改成按回路编号比较就行了。 /* Footprints In The Blood Soaked Snow */ #include #include using namespace std; const int maxm = 10005, maxn = maxm << 2,原创 2016-03-09 21:59:29 · 785 阅读 · 0 评论 -
【POJ1637】Sightseeing tour【最大流】【混合图欧拉回路】
【题目链接】 混合图欧拉回路。 论文题,见【网络流建模汇总】 注意入度大于出度必须连接汇点,出度大于入度必须源点去连。不能相反。 /* Pigonometry */ #include #include using namespace std; const int maxn = 205, maxm = 5005, maxq = 10000, inf = 0x3f3f3原创 2016-04-04 20:23:22 · 455 阅读 · 0 评论