예제 #1
0
파일: BZOJ1877.cpp 프로젝트: mayukuner/AC
  bool spfa(int &flow,int &cost){
    memset(dist,0x3f,sizeof(dist));
    dist[S]=0;
    q.init(N);
    q.push(S);
    while(!q.empty()){
     int u=q.front();
      q.pop();
      for(int i=le[u]; i!=-1; i=pe[i]){
	Edge &e=edges[i];
	if(e.data){
	  if(dist[e.v]>dist[u]+e.cost){
	    dist[e.v]=dist[u]+e.cost;
	    pre[e.v]=i;
	    q.push(e.v);
	  }
	}
      }
    }
    if(dist[T]>=INF)return false;
    int u=T;
    while(u!=S){
      Edge &e=edges[pre[u]];
      edges[pre[u]].data--;
      edges[1^pre[u]].data++;
      u=edges[pre[u]].u;
    }
    cost+=dist[T];
    flow++;
    return true;
  }
예제 #2
0
 typename std::enable_if<container_traits::has_pop<S>::value, void>::type
 pop_adapter () { queue.pop (); };