Language: C++

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

enum { MAXV = 50 + 10, INF = 100000000 };
struct edge
{
    int to, cap, rev;
};

vector <edge> G[MAXV];
int level[MAXV];
int iter[MAXV];
int n;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};

void init()
{
    memset(markG, 0, sizeof markG);
    for(int i = 0; i < MAXV * MAXV; i++) G[i].clear();
}

void coorConv(int &x, int &y)
{
    int t1 = x, t2 = y;
    y = t1 - 1, x = n - t2;
}

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

void construct()
{
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(i != 0 && i != n - 1 && j != 0 && j != m - 1)
            {
                for(int k = 0; k < 4; k++)
                {
                    int tx = i + dx[k], ty = j + dy[k];
                    if(tx >= 0 && tx < n && ty >= 0 && ty < m && markG[tx][ty] != -1)
                    {
                        add_edge(i * n + j + 1 , tx * n + ty + 1, 1);
                    }
                }
            }
        }
    }
}

void bfs(int s)
{
    memset(level, -1, sizeof(level));
    queue <int> q;
    level[s] = 0;
    q.push(s);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(int i = 0; i < G[v].size(); i++)
        {
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0)
            {
                level[e.to] = level[v] + 1;
                q.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f)
{
    //cout << v <<" " << t<<" " << f<<endl;
    if(v == t) return f;
    for(int i = iter[v]; i < G[v].size(); i++)
    {
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to])
        {
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0)
            {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t)
{
    int flow = 0;
    for(;;)
    {
        bfs(s);
        if(level[t] < 0) return flow;
        memset(iter, 0, sizeof iter);
        int f;
        while((f = dfs(s, t , INF)) > 0) flow += f;
        //cout <<"flow: "<< flow <<endl;
    }
}

int main()
{
    int cnt = 0;
    while(~scanf("%d", &n))
    {
        int s, t, m;
        scanf("%d%d%d", &s, &t, &m);
        for(int i = 0; i < m; i++)
        {
            int tx, ty, cap;
            scanf("%d%d%d", &tx, &ty, &cap);
            add_edge(tx, ty, cap);
        }
        cout << max_flow(s, t) << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'void init()':
a.cc:19:12: error: 'markG' was not declared in this scope
   19 |     memset(markG, 0, sizeof markG);
      |            ^~~~~
a.cc: In function 'void add_edge(int, int, int)':
a.cc:33:28: warning: narrowing conversion of 'G[to].std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   33 |         to, cap, G[to].size()
      |                  ~~~~~~~~~~^~
a.cc:37:33: warning: narrowing conversion of '(G[from].std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   37 |         from, 0, G[from].size() - 1
      |                  ~~~~~~~~~~~~~~~^~~
a.cc: In function 'void construct()':
a.cc:45:28: error: 'm' was not declared in this scope
   45 |         for(int j = 0; j < m; j++)
      |                            ^
a.cc:52:66: error: 'markG' was not declared in this scope
   52 |                     if(tx >= 0 && tx < n && ty >= 0 && ty < m && markG[tx][ty] != -1)
      |                                                                  ^~~~~