记录编号 431137 评测结果 AAAAAAAAAA
题目名称 运输问题4 最终得分 100
用户昵称 GravatarHallmeow 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2017-07-31 10:40:06 内存使用 0.00 MiB
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cstring>
using namespace std;
#define LL long long
#define pos(i,a,b) for(int i=(a);i<=(b);i++)
#define N 10000
#define inf 0x7fffffff
struct haha{
	int next,to,w,cost,from;
}edge[N];
int cnt=2,head[N];
int n,s,t;
inline int read(){
  int x=0,f=1;
  char ch=getchar();
  while(ch<'0'||ch>'9'){
    if(ch=='-') f=-1;
    ch=getchar();
  }
  while(ch>='0'&&ch<='9'){
    x=(x<<3)+(x<<1)+ch-'0';
    ch=getchar();
  }
  return x*f;
}
inline void add(int u,int v,int w,int c){
	edge[cnt].w=w;
	edge[cnt].to=v;
	edge[cnt].cost=c;
	edge[cnt].from=u;
	edge[cnt].next=head[u];
	head[u]=cnt++;
}
int dis[N],flag[N],from[N];
queue<int> q;
inline int spfa(int st,int ed)
{
	  pos(i,st+1,ed){
	  	dis[i]=inf;
	  }
	  flag[st]=1;
	  q.push(st); 
	  while(!q.empty())
	  {
	    int k=q.front();
	    q.pop();
	    flag[k]=0;
	    for(int i=head[k];i;i=edge[i].next)
	    {
	      if(edge[i].w&&dis[edge[i].to]>dis[k]+edge[i].cost)
	      {
	        dis[edge[i].to]=dis[k]+edge[i].cost;
	        if(!flag[edge[i].to])
			  q.push(edge[i].to);
	        flag[edge[i].to]=1;
			from[edge[i].to]=i;
	      }
	    }
	  }
	  if(dis[ed]==inf)
	    return 0;
	  return dis[ed];
}
inline int work(int st,int ed)
{
	  int pp=ed,ff=inf;
	  while(pp!=st)
	  {
	    ff=min(ff,edge[from[pp]].w);
	    pp=edge[from[pp]^1].to;
	  }
	  pp=ed;
	  while(pp!=st)
	  {
	    edge[from[pp]].w-=ff;
	    edge[from[pp]^1].w+=ff;
	    pp=edge[from[pp]^1].to;
	  }
	  return ff;
}
inline int MCMF(int st,int ed)
{
	  int ret=0,l;
	  while(l=spfa(st,ed))
	    ret+=work(st,ed)*l;
	  return ret;
}
/*int spfa(int st,int ed){
	queue<int> q;
	pos(i,st+1,ed){
		dis[i]=inf;
	}
	flag[st]=1;
	q.push(st);
	while(!q.empty()){
		int k=q.front();
		q.pop();
		flag[k]=0;
		for(int i=head[k];i;i=edge[i].next){
			int to=edge[i].to,cost=edge[i].cost,w=edge[i].w;
			if(w&&dis[to]>dis[k]+cost){
				dis[to]=dis[k]+cost;
				if(!flag[to])
				  q.push(to);
				flag[to]=1;
				flag[to]=i;
			}
		}
	}
	if(dis[ed]==inf){
		return 0;
	}
	return dis[ed];
}
int work(int st,int ed){
	int p=ed,f=inf;
	while(p!=st){
		f=min(f,edge[from[p]].w);
		p=edge[from[p]^1].to;
	}
	p=ed;
	while(p!=st){
		edge[from[p]].w-=f;
		edge[from[p]^1].w+=f;
		p=edge[from[p]^1].to;
	}
	return f;
}
int get(int st,int ed){
	int ret=0,l;
	while(l=spfa(st,ed))
	  ret+=work(st,ed)*l;
	return ret;
}*/
int cun[300][300],ans;
int messi(){
	freopen("maxflowd.in","r",stdin);
	freopen("maxflowd.out","w",stdout);
	n=read();s=read();t=read();
	pos(i,1,n){
		pos(j,1,2*n){
			cun[i][j]=read();
		}
	}
	pos(i,1,n){
		for(int j=1;j<=2*n;j+=2){
			int temp=(j+1)/2;
			if(i!=temp&&cun[i][j]){
				//cout<<"i="<<i<<"   temp="<<temp<<"  cun[i][j]="<<cun[i][j]<<endl;
				add(i,temp,cun[i][j],cun[i][j+1]);
				add(temp,i,0,-cun[i][j+1]);
			}
			
		}
	}
	ans=MCMF(s,t);
	cout<<ans;
	return 0;
}
int hallmeow=messi();
int main(){
	;
}