随笔分类 -  网络流

摘要:模板题,不解释了 阅读全文
posted @ 2012-02-22 16:04 Because Of You 阅读(204) 评论(0) 推荐(0)
摘要:首先注意边是双向边,最短路的inf要取很大思路:增加一个源点,一个汇点,如果一个避雨点有a只奶牛,则从源点向这个点连一条边,容量为a,如果这个避雨点能容纳b只奶牛,则从这个点向汇点连一条容量为b的边。接着二分枚举答案,两点间最短路径的长度小于等于二分值的两个点能互相到达,连一条容量为无穷大的边这样子建好图后求最大流会发现样例都过不了,debug过程中发现如果1->2 , 2->3,那么1就会自动联通3,实际上1,3可能不连通,所以想到把点拆成两排,如果1,2连通,就从1连一条边到2+n,这样就不会出现上面的情况了,另外,连接汇点的点变成了n+1---2*n。敲完后果断还是WA,都快 阅读全文
posted @ 2012-02-22 15:18 Because Of You 阅读(435) 评论(0) 推荐(0)
摘要:题意:安排C头奶牛到K个挤奶器,每个挤奶器最多能为M头牛挤奶,给出奶牛、挤奶器之间的额边的权值,求所有安排方案中,C头奶牛需要走的最大距离的最小值先求好原图中两两间的最短路径,再二分答案,验证是否能满足C头奶牛都能到达挤奶器,能的话就继续缩小范围具体验证方法:增加一个汇点,每个挤奶器向汇点连上一条容量为M的边,增加一个源点,向每只牛连一条容量为1的边,然后求一个s--t的最大流即可View Code #include<iostream>#include<string.h>#include<stdio.h>#include<queue>#defin 阅读全文
posted @ 2012-02-21 21:50 Because Of You 阅读(350) 评论(0) 推荐(0)
摘要:#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define SIZE 1010const int inf = 100000000;struct node{ int s,t,f,w; int next;}edge[100010];int head[2010];int mincost,tot;int s,t,pre[2010];void add(int s,int t,int w,int f){ edge[tot].f 阅读全文
posted @ 2011-11-24 23:49 Because Of You 阅读(612) 评论(0) 推荐(0)
摘要:使用了书上讲的迭代加深搜索,假设删除一个点,两个点,三个点。。。每次都先找最短路径再枚举最短路径上的点删除,dfs实现,A的很顺利,呵呵。。View Code 1 #include<stdio.h> 2 #include<string.h> 3 int n,m,k; 4 int tot; 5 bool goal; 6 int fa[60]; 7 bool flag[60]; 8 int d[50][100]; 9 int head[60];10 int Q[10000];11 struct node12 {13 int t,next;14 }edge[10005];15 阅读全文
posted @ 2011-11-01 21:03 Because Of You 阅读(486) 评论(4) 推荐(0)
摘要:求割点数很简单难在一些细节到现在还不清楚为什么一开始就设置dfn为1为什么会错错误的代码View Code #include<stdio.h>#include<string.h>int n,son,ans;int map[1000][1000];int dfn[1000],low[1000];int vis[1000];int tdfn;int flag[1000];int min(int a,int b){ return a<b?a:b;}void dfs(int u){ int v; for(v=1;v<=n;v++){ if(map[u][v]){ . 阅读全文
posted @ 2011-10-10 12:19 Because Of You 阅读(274) 评论(0) 推荐(0)
摘要:顶点连通度:即最少去掉几个点使得图不连通设想两个不相邻的点u,v;从u到v的两条没有公共内部顶点的路径,互称为独立轨,;u到v独立轨最大的条数,记作P(u,v)所以要想图不联通,应该在每条独立轨上都去掉一个点(不能随便去),所以顶点连通度就是最大独立轨数目的最小值注意,如果图是完全图,应该去掉所有的点怎么求两点间(A,B)的最大独立轨P(A,B)呢?1、把每个点都拆成两个点,之间连一条容量为1的边u'---u",原图中的每条边e=(u,v)在新网络中有两条弧e'=<u",v'>和e"=<v",u'> 阅读全文
posted @ 2011-10-09 12:44 Because Of You 阅读(660) 评论(1) 推荐(0)
摘要:记住,这是china算法,呵呵,一丝悲哀,又有一丝欣慰第一次做,用的是矩阵版本的,但貌似对于数据更大的情况要用邻接表的,继续学习View Code #include<stdio.h>#include<math.h>#include<string.h>#define INF 100000000#define min(a,b) a<b?a:bint n,m;double map[110][110];int vis[110],pre[110];int circle[110]; struct { int x,y;}node[110];double dist(i 阅读全文
posted @ 2011-09-06 11:44 Because Of You 阅读(293) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>#define min(a,b)(a<b?a:b)#define INF 9999999#define MAX 1005int S,N,end,M;int cap[MAX][MAX],flow[MAX],p[MAX];int room[MAX],belong[MAX];int q[10000];int bfs(){ int u,i; for(i=0;i<MAX;i++) { flow[i]=INF; p[i]=-1; } p[S]=0; in... 阅读全文
posted @ 2011-09-01 12:27 Because Of You 阅读(196) 评论(0) 推荐(0)