Exemple #1
0
int Max_Flow()
{
   int flow=0,left;
   while(Bfs())
      while(left=Dinic(S,inf))flow+=left;
   return flow;
}
Exemple #2
0
	void Work(void) {
		int A = 0, last = 0, t;
		for (int i = 1;; i++) {
			Add();
			if (last + (t = Dinic()) == m) {
				A = i;
				break;
			}
			last += t;
		}
		printf("%d\n", A);
	}
Exemple #3
0
int Dinic(int now,int left)
{
   if(now==T)return left;
   int aug=0,temp,k,add;
   for(temp=start[now];temp!=0;temp=edge[temp].next)
      if(dist[edge[temp].e]==dist[now]+1&&edge[temp].l>0)
         if(add=Dinic(edge[temp].e,Min(left-aug,edge[temp].l)))
         {
            aug+=add;
            k=(temp&1)?temp+1:temp-1;
            edge[temp].l-=add;
            edge[k].l+=add;
         }
   if(!aug)dist[now]=-1;
   return aug;
}
Exemple #4
0
int main(){
    read();
    Dinic();
    for(int i=1;i<=T;i++){
        for(int j=head[i];j;j=E[j].next){
            if(E[j].a>0){
                if(E[j].f) addedge(i,E[j].v,E[j].f,0);
                E[j].f=INF;
            }
            else E[j].a=0;//去掉有负环 
        }
    }
    while(SPFA());
    printf("%d",mcost);
    return 0;
}
Exemple #5
0
	void Work(void) {
		Input();
		for (long i = 1; i <= n; i++)
			for (long j = 1; j <= m; j++) {
				if (map[i][j] == 1)
					Add(vs, G(i, j), inf);
				else if (map[i][j] == 2)
					Add(G(i ,j), vt, inf);
				for (long k = 0; k < 4; k++) {
					long x = i + fim[k][0], y = j + fim[k][1];
					if (x > 0 && x <= n && y > 0 && y <= m) {
						if (map[x][y] == map[i][j] && map[i][j])
							Add(G(i, j), G(x, y), 0);
						else
							Add(G(i ,j), G(x, y), 1);
					}
				}
			}
		printf("%ld\n", Dinic());
	}