Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage…
#include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i<=f_end;i++) #define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr)) ; ; int size; int n; const int inf=0x3f3f3f3f; using namespace std; int head[maxn];…
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; , INF = 0x7fffffff; int d[maxn], head[maxn]; int n, m, s, t; struct edge{ int u, v, f, c, next; }…
//这个是邻接矩阵的#include<iostream> #include<queue> #include<string.h> #include<stdio.h> #include<algorithm> using namespace std; ; const int inf=0x3f3f3f; int N; int depth[maxn]; int a[maxn][maxn]; bool bfs(int s,int e)//广搜求深度 { qu…
hdu1532 输入n,m. n条边,m个点,之后给出a到b的容量,求1到m的最大流. 注意:Dinic只能调用一次,因为原理是改变cap的值,如果调用多次一样的,那么第一次会对,其余的都会是0,因为,cap的值经过一次调用已经改变了,如果想调用多次,就只能再开一个数组,存下原来的cap值. #include <bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; typedef long long LL; #define…
ISAP // UVa11248 Frequency Hopping:使用ISAP算法,加优化 // Rujia Liu struct Edge { int from, to, cap, flow; }; struct ISAP { int n, m, s, t; vector<Edge> edges; vector<int> G[maxn]; // 邻接表,G[i][j]表示结点i的第j条边在e数组中的序号 bool vis[maxn]; // BFS使用 int d[maxn]…
//网络流SAP模板,复杂度O(N^2*M) //使用前调用init(源点,汇点,图中点的个数),然后调用add_edge()加边 //调用getflow得出最大流 #define N 55 #define M 500500 #define INF 0x3fffff struct Max_Flow { struct node { int to,w,next; }edge[M]; int s,t; int nn; int cnt,pre[N]; int lv[N],gap[N]; void ini…