解法:
好水的最小割。不就是套路吗。。。
首先先把所有的行跟列加起来。
因为你最多最多只需要这么多啊。
然后一个士兵可能会有两次贡献(一次行,一次列)
就相当于找尽量多的贡献为2的士兵。
按照这个图去建最小割即可。
代码实现:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
struct node {int x,y,c,next,other;}a[210000];int len,last[110000];
void ins(int x,int y,int c) {
int k1,k2;
len++;k1=len;a[len].x=x;a[len].y=y;a[len].c=c;a[len].next=last[x];last[x]=len;
len++;k2=len;a[len].x=y;a[len].y=x;a[len].c=0;a[len].next=last[y];last[y]=len;
a[k1].other=k2;a[k2].other=k1;
}
int head,tail,list[110000],h[1100],st,ed;
bool bt_h() {
head=1;tail=2;list[1]=st;memset(h,0,sizeof(h));h[st]=1;
while(head!=tail) {
int x=list[head];
for(int k=last[x];k;k=a[k].next) {
int y=a[k].y;
if(h[y]==0&&a[k].c>0) {h[y]=h[x]+1;list[tail++]=y;}
}head++;
}if(h[ed]==0)return false;return true;
}
int find_flow(int x,int f) {
if(x==ed)return f;
int s=0,t;
for(int k=last[x];k;k=a[k].next) {
int y=a[k].y;
if(h[y]==h[x]+1&&a[k].c>0&&s<f) {
t=find_flow(y,min(a[k].c,f-s));s+=t;a[k].c-=t;a[a[k].other].c+=t;
}
}if(s==0)h[x]=0;return s;
}
bool map[110][110];int n,m;
int H[110],l[110];
int main() {
int K;scanf("%d%d%d",&n,&m,&K);st=n+m+1;ed=st+1;
len=0;memset(last,0,sizeof(last));memset(map,true,sizeof(map));int sum=0;
for(int i=1;i<=n;i++){scanf("%d",&H[i]);ins(st,i,H[i]);sum+=H[i];}
for(int i=1;i<=m;i++){scanf("%d",&l[i]);ins(i+n,ed,l[i]);sum+=l[i];}
for(int i=1;i<=K;i++) {int x,y;scanf("%d%d",&x,&y);map[x][y]=false;H[x]++;l[y]++;}
bool bk=true;
for(int i=1;i<=n;i++)if(H[i]>m) {bk=false;break;}
for(int i=1;i<=m;i++)if(l[i]>n) {bk=false;break;}
if(bk==false) {printf("JIONG!\n");return 0;}
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) {
if(map[i][j]==true)ins(i,j+n,1);
}
int ans=0;while(bt_h()==true)ans+=find_flow(st,999999999);printf("%d\n",sum-ans);
return 0;
}