听说灌水区大佬多,求助一个网络流的题
  • 板块灌水区
  • 楼主0tAp
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/2/27 22:32
  • 上次更新2024/2/28 14:28:30
查看原帖
听说灌水区大佬多,求助一个网络流的题
758858
0tAp楼主2024/2/27 22:32

P2740

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
const int N=210,M=5e3+10;
int _map[M][M],pre[M];
int vis[M];
int n,m,s,t;

void _update_(int u,int flow)
{
	while(pre[u]!=-1)
	{
		_map[pre[u]][u]-=flow;
		_map[u][pre[u]]+=flow;
		u=pre[u];
	}
}


int _find_path_(int s,int t)
{
	memset(vis,0,sizeof vis);
	memset(pre,-1,sizeof pre);
	vis[s]=1;
	int min_flow=1e9+10;
	queue<int>q;
	q.push(s);
	
	while(!q.empty())
	{
		int u=q.front();q.pop();
		if(u==t)break;
		rep(i,1,m)
		{
			if(vis[i]==0&&_map[u][i]!=0)
			{
				q.push(i);
				min_flow=min(min_flow,_map[u][i]);
				pre[i]=u;
				vis[i]=1;
			}
		}
	}
	if(pre[t]==-1)return 0;
	return min_flow;
}

int _EK_(int s,int t)
{
	int new_flow=0,max_flow=0;
	do{
		new_flow=_find_path_(s,t);
		_update_(t,new_flow);
		max_flow+=new_flow;
	}while(new_flow!=0);
	return max_flow;
}

int main()
{
	cin>>m>>n;
	rep(i,1,m)
	{
		int u,v,w;
		cin>>u>>v>>w;
		_map[u][v]=w;
	}
	int ans=_EK_(1,n);
	cout<<ans;
}

wa#2,#12

请大佬们帮忙看看,谢谢

2024/2/27 22:32
加载中...