Language: C++

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;

struct MCF{
    struct edge{
        int to,cost,cap,rev;
        edge(int to,int cap,int cost,int rev):to(to),cost(cost),cap(cap),rev(rev){}
    };

    int V;
    vector<vector<edge>>G;
    vector<int>h;
    vector<int>dist;
    vector<int>prevv,preve;

    MCF(int v):V(v){
        G.resize(V);
        h.resize(V);
        dist.resize(V);
        prevv.resize(V);
        preve.resize(V);
    }

    void addEdge(int from,int to,int cap,int cost){
        G[from].push_back(edge(to,cap,cost,G[to].size()));
        G[to].push_back(edge(from,0,-cost,G[from].size()-1));
    }

    int minCostFlow(int s,int t,int f){
        int res=0;
        fill(h.begin(),h.end(),0);
        while(f>0){
            priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>que;
            que.push({0,s});
            fill(dist.begin(),dist.end(),INF);
            dist[s]=0;

            while(que.size()){
                int c,v;
                tie(c,v)=que.top();
                que.pop();
                if(dist[v]<c)continue;
                for(int i=0;i<G[v].size();i++){
                    edge &e=G[v][i];
                    if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                        dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
                        prevv[e.to]=v;
                        preve[e.to]=i;
                        que.push({dist[e.to],e.to});
                    }
                }
            }
            if(dist[t]==INF)return -1;
            for(int v=0;v<V;v++){
                h[v]+=dist[v];
            }

            int d=f;
            for(int v=t;v!=s;v=prevv[v]){
                d=min(d,G[prevv[v]][preve[v]].cap);
            }
            f-=d;
            res+=d*h[t];
            for(int v=t;v!=s;v=prevv[v]){
                edge &e=G[prevv[v]][preve[v]];
                e.cap-=d;
                G[v][e.rev].cap+=d;
            }
        }
        return res;
    }
};

int N;
int U[333],D[333],L[333],R[333];

signed main(){
    cin>>N;
    rep(i,N)cin>>U[i];
    rep(i,N)cin>>D[i];
    rep(i,N)cin>>L[i];
    rep(i,N)cin>>R[i];

    /*
    MCF mcf(N*N+4*N+2);
    int src=N*N+4*N;
    int snk=N*N+4*N+1;

    rep(i,N){
        mcf.addEdge(src,N*N+i,U[i],0);
        mcf.addEdge(src,N*N+N+i,D[i],0);
        mcf.addEdge(src,N*N+2*N+i,L[i],0);
        mcf.addEdge(src,N*N+3*N+i,R[i],0);

    }
    rep(i,N)rep(j,N){
        mcf.addEdge(i*N+j,snk,1,0);
        mcf.addEdge(N*N+j,i*N+j,1,i);
        mcf.addEdge(N*N+N+j,i*N+j,1,N-1-i);
        mcf.addEdge(N*N+2*N+i,i*N+j,1,j);
        mcf.addEdge(N*N+3*N+i,i*N+j,1,N-1-j);
    }*/

    MCF mcf(3*N*N+2);
    int src=3*N*N;
    int snk=3*N*N+1;

    rep(i,N){
        mcf.addEdge(src,i,U[i],0);
        mcf.addEdge(src,(N-1)*N+i,D[i],0);
        mcf.addEdge(src,N*N+i*N,L[i],0);
        mcf.addEdge(src,N*N+i*N+N-1,R[i],0);
    }

    rep(i,N){
        rep(j,N){
            if(i)mcf.addEdge(i*N+j,(i-1)*N+j,INF,1);
            if(i+1<N)mcf.addEdge(i*N+j,(i+1)*N+j,INF,1);
            if(j)mcf.addEdge(N*N+i*N+j,N*N+i*N+j-1,INF,1);
            if(j+1<N)mcf.addEdge(N*N+i*N+j,N*N+i*N+j+1,INF,1);
            mcf.addEdge(i*N+j,N*N*2+i*N+j,1,0);
            mcf.addEdge(N*N+i*N+j,N*N*2+i*N+j,1,0);
            mcf.addEdge(N*N*2+i*N+j,snk,1,0);
        }
    }


    int tmp=mcf.mincostFlow(src,snk,N*N);
    if(tmp==-1){
        cout<<"NO"<<endl;
        return 0;
    }
    
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:144:17: error: 'struct MCF' has no member named 'mincostFlow'; did you mean 'minCostFlow'?
  144 |     int tmp=mcf.mincostFlow(src,snk,N*N);
      |                 ^~~~~~~~~~~
      |                 minCostFlow