![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论
文章平均质量分 74
birdforever
我是一个纯粹的人,生不带来,死不带走,只为无怨无悔地活一次!
展开
-
poj 1161 Walls
<br />//poj 1161 Walls 平面图的对偶图 <br />/* <br />题解: 求平面图的对偶图,然后按题意枚举见面地点就好了。<br />PS: 这题WA了N次,有点绝望,错在把n个点也加入图,分别<br />与它所属的几个面相连,这样就会造成原本不相连的面可能会<br />通过某个点相连。<br />*/<br />#include <iostream><br />#include <vector><br />using namespace std;<br />const int i原创 2010-08-24 23:29:00 · 515 阅读 · 0 评论 -
poj 1158 TRAFFIC LIGHTS
<br />// poj 1158 TRAFFIC LIGHTS (Dijkstra算法的应用)/*其实最短路的裸题几乎不会出现,要学的是最优路径的性质的应用,本题虽然加了个时间限制,但如果能看穿并证明其仍旧符合最优路径性质,那问题就迎刃而解了。 */ #include <iostream>using namespace std;const int inf = 1<<26;int n,m;struct node{ int color,r,ti[2];原创 2010-09-06 00:21:00 · 1134 阅读 · 0 评论 -
poj 1149 PIGS
<br />// poj 1149 PIGS (网络流)/*网络流构图,用sap邻接表版过的,一开始用邻接阵,因为点有两千多个就MLE了,构图如下: 1. 源点s到客户连边,权值为客户所需求量 2. 客户到他所能打开的猪圈连边,权值为inf 3. 如果客户i能打开猪圈k,客户j(j<i) 也能打开猪圈k,则i连边到j(只连一次),权值为inf4. 猪圈i拆点,i-i' 权值为猪圈中猪数量5. 猪圈i' 到汇点 t 连边,权值为inf */ #include <iost原创 2010-09-06 00:19:00 · 697 阅读 · 0 评论 -
poj 1041 Eulerian Circuit
<br />/* source code of submission 363011, Zhongshan University Online Judge System */<br />/* source code of submission 362793, Zhongshan University Online Judge System */<br />#include <iostream><br />#include <cstdlib><br />#include <algorithm><br />#in原创 2010-08-31 21:09:00 · 714 阅读 · 0 评论 -
sap(邻接阵)模板
<br />//EK,SAP,DINIC三种算法以及它们的表和阵两个版本的效率,已在sicily1423. 魔王bug的2色定理上验证过,//显然SAP,DINIC要快很多,SAP和DINIC相差不大。但因为DINIC每次要重新构层次图,可能相对会慢一点。const int VMAX = 500;int n,m,s,t;int r[VMAX+10][VMAX+10];int gap[VMAX+10],pre[VMAX+10],dis[VMAX+10];//int cur[VMAX+1原创 2010-09-10 01:45:00 · 108 阅读 · 0 评论 -
dinic(邻接表)模板
<br />//用它做过一些题(hdu3046,poj3469等),正确性和效率都有待改进//主要难题:如何在用邻接表表示余留网时迅速找到一条边的逆边?const int null = -1;const int VMAX = 40000;const int EMAX = 160000;struct Edge{ int adj,next,re; //指向的点,下一边的下标,逆边的下标 int r; //余留网边的容量}h[EMAX+10];原创 2010-09-10 01:44:00 · 1184 阅读 · 0 评论 -
EK(邻接阵)模板
<br />int n,s,t;const int VMAX = 500;int r[VMAX+10][VMAX+10];int mark[VMAX+10],pre[VMAX+10];int EK(){ int ans=0; int head,tail; while (1) { memset(mark,0,sizeof(mark)); mark[s]=1; head=tail=0; Q[tail++]=s; while (head<tai原创 2010-09-10 01:41:00 · 402 阅读 · 0 评论 -
poj 2396 Budget
<br /><br />//POJ 2396 上下界可行流<br />//引用这位仁兄的解题报告:http://hi.baidu.com/zfy0701/blog/item/6449d82a64e15e3e5343c1ba.html<br />#include <iostream><br />#include <algorithm><br />using namespace std;<br />const int inf=1<<28;<br />int n,m,s,t,ds,dt;<br />const原创 2010-09-01 21:41:00 · 686 阅读 · 0 评论 -
sap(邻接表)模板
<br />const int null = -1;const int VMAX = 500;const int EMAX = 300000;struct Edge{ int adj,next,re; //指向的点,下一边的下标,逆边的下标 int r; //余留网边的容量}h[EMAX+10]; //用下标模拟指针构邻接表int p[VMAX+10],c;int n,m,s,t;int gap[VMAX+10],pre[VMAX+10]原创 2010-09-11 11:08:00 · 866 阅读 · 0 评论 -
dinic(邻接阵)模板
<br />//做Hust的dance party时候学的一个板,以后记得常用哈,错的才可以改进。const int VMAX = 400;int r[VMAX+10][VMAX+10]; //余留网int Q[VMAX+10],level[VMAX+10]; //用于bfs的队列和各点层次//广搜求层次图bool bfs(){ memset(level,-1,sizeof(level)); int head=0,tail=0; Q[tail++]=s;原创 2010-09-10 01:43:00 · 521 阅读 · 0 评论 -
EK(邻接表)模板
<br />const int null = -1;const int VMAX = 60000;const int EMAX = 1000000;struct Edge{ int adj,next,re; //指向的点,下一边的下标,逆边的下标 int r; //余留网边的容量}h[EMAX+10]; //用下标模拟指针构邻接表int n,m,s,t;int p[VMAX+10],c; //各点的头指针,目前h数组开到原创 2010-09-10 01:42:00 · 594 阅读 · 0 评论 -
poj 1523 SPF
<br />#include <iostream><br />#include <cstdlib><br />#include <cmath><br />#include <algorithm><br />using namespace std;<br />//poj1523<br />int con[1010][1010]; //图的邻接矩阵 <br />int low[1010]; <br />int mark[1010];<br />bool iscut[1010]; //标原创 2010-08-30 00:33:00 · 387 阅读 · 0 评论 -
poj 2226 Muddy Fields
<br />//POJ2226 最小点覆盖=最大二分匹配<br />//难在构图,其实边数就是星的个数<br />//要求覆盖所有的星的最少板数就是求最小点覆盖<br />#include <cstdio><br />#include <cmath><br />#include <cstring><br />#include <ctime><br />using namespace std;<br />char grid[60][60];<br />int bigraph[2000][2000];<br /原创 2010-08-30 00:25:00 · 450 阅读 · 0 评论 -
最佳匹配KM算法模板
<br /> <br />#include <stdio.h><br />#include <string.h><br />#define N 1001<br />#define M 1<<30<br />int n;<br />int m[N][N]={0};<br />int link[N]={0};<br />int lx[N]={0},ly[N]={0};<br />bool x[N]={0},y[N]={0};<br />int Min(int a,int b) {return a<b?a:b;}原创 2010-08-27 19:13:00 · 773 阅读 · 0 评论 -
poj 3020 Antenna Placement
<br />#include <iostream><br />using namespace std;<br />int l,c;<br />char place[45][15];<br />int graph[600][600];<br />int used[600];<br />int link[600];<br />int hash[500];<br />int sum;<br />void side(int v,int w) //与相邻点加边到graph图里<br />{<br /> int x,原创 2010-08-26 00:32:00 · 372 阅读 · 0 评论 -
poj 1201 Intervals
<br />//poj 1201 Intervals(1716为简单版) 差分约束<br />/* <br />题解: 第一道差分约束,转化为求最长路径。<br />引用:http://www.cppblog.com/initiate/archive/2010/04/03/111530.aspx<br />*/<br />#include <iostream><br />#include <vector><br />using namespace std;<br />const int size = 50原创 2010-08-25 00:10:00 · 412 阅读 · 0 评论 -
poj 1386 Play on Words
<br />//poj 1386 Play on Words 欧拉回路<br />/*<br />注意连通性,为此WA了很多次哎。。。<br />*/<br />#include <iostream><br />#include <algorithm><br />using namespace std;<br />const int inf = 1<<28;<br />int n,m;<br />int in[26],out[26],con[26][26],mark[26];<br />char input原创 2010-08-24 23:19:00 · 473 阅读 · 0 评论 -
poj 2762 Going from u to v or from v to u?
<br />// poj 2762 Going from u to v or from v to u?/*题意: 判断一个有向图中是否任意两点都至少满足一点到另一点可达题解: Robert Sedgewick著《C++算法--图算法》P179PS: 由于作业比较多,做题时间有限,未做太多优化,望见谅*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;int n,m;原创 2010-10-21 16:51:00 · 683 阅读 · 0 评论