蒟蒻在AcWing上过了这个题,但交了后全t飞了 求巨佬帮调qwq
(评测记录) https://www.luogu.com.cn/record/68287680
下附代码
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 20200
#define M 200200
using namespace std;
const int INF = 1e8;
int head[N],Next[M],ver[M],edge[M],tot=-1;
int val[M],q[N],d[N],incf[N],pre[N],n,m,s,t;
bool st[N];
void ADD(int x,int y,int z,int w){
ver[++tot]=y;edge[tot]=z;
val[tot]=w;Next[tot]=head[x];head[x]=tot;
ver[++tot]=x;edge[tot]=0;
val[tot]=-w;Next[tot]=head[y];head[y]=tot;
}
int spfa(){
int f=0,r=0;
memset(d,-0x3f,sizeof(d));
memset(incf,0,sizeof(incf));
q[r++]=s;d[s]=0;incf[s]=INF;
while(f!=r){
int x=q[f++];
if(f==N) f=0;
st[x]=false;
for(int i=head[x];~i;i=Next[i]){
int y=ver[i];
if(d[x]+val[i]>d[y]/**/&&edge[i]){
pre[y]=i;
d[y]=d[x]+val[i];
incf[y]=min(edge[i],incf[x]);
if(!st[y]){
st[y]=true;
q[r++]=y;
if(r==N) r=0;
}
}
}
}
return incf[t]>0;
}
int EK(int &flow,int &cost){
flow=cost=0;
while(spfa()){
flow+=incf[t];
cost+=incf[t]*d[t];
for(int i=t;i!=s;i=ver[pre[i]^1]){
edge[pre[i]]-=incf[t];
edge[pre[i]^1]+=incf[t];
}
}
}
int get(int i,int j){
return i*16+j;
}
int main(){
memset(head,-1,sizeof(head));
s=N-3;t=N-2;
int a,b,p,q,x,y,k;
scanf("%d%d",&a,&b);
scanf("%d%d",&p,&q);
for(int i=0;i<=p;i++){
for(int j=0;j<q;j++){
scanf("%d",&x);
ADD(get(i,j),get(i,j+1),1,x);
ADD(get(i,j),get(i,j+1),INF,0);
}
}
for(int j=0;j<=q;j++){
for(int i=0;i<p;i++){
scanf("%d",&x);
ADD(get(i,j),get(i+1,j),1,x);
ADD(get(i,j),get(i+1,j),INF,0);
}
}
for(int i=1;i<=a;i++){
scanf("%d%d%d",&k,&x,&y);
ADD(s,get(x,y),k,0);
}
for(int i=1;i<=b;i++){
scanf("%d%d%d",&k,&x,&y);
ADD(get(x,y),t,k,0);
}
int flow,cost;
EK(flow,cost);
printf("%d\n",cost);
return 0;
}