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; }
typename std::enable_if<container_traits::has_front<S>::value, const T&>::type front_adapter () const { return queue.front(); };