Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <tuple>
using namespace std;
struct edge{
    int to;
    int cap;
    int rev;
};
struct Dinic{
    int V;
    vector<int> level, used;
    vector<vector<edge>> G;
    Dinic(int N){
        V = N;
        used.resize(V, 0);
        level.resize(V, -1);
        G.resize(V);
    }
    void add(int u, int v, long long c){
        edge e1 = {v, c, (int)G[v].size()};
        G[u].push_back(e1);
        edge e2 = {u, 0, (int)G[u].size() - 1};
        G[v].push_back(e2);
    }
    void bfs(int s){
        level.assign(V, -1);
        queue<int> q;
        q.push(s);
        level[s] = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(edge e: G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    long long dfs(int s, int t, long long f){
        if(s == t) return f;
        for(int &i = used[s]; i < (int)G[s].size(); i++){
            edge &e = G[s][i];
            if(e.cap > 0 && level[e.to] > level[s]){
                long long 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 solve(int s, int t){
        int flow = 0;
        int INF = 1e9;
        while(1){
            bfs(s);
            if(level[t] < 0) return flow;
            used.assign(V, 0);
            int f;
            while((f = dfs(s, t, INF)) > 0) flow += f;
        }
    }
};
int main(){
    int N, M;
    cin >> N >> M;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
    Dinic D(N * M + 2);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(S[i][j] == '#') continue;
            if((i + j) % 2 == 1){
                int s = i * M + j;
                D.add(N * M, s, 1);
                for(int k = 0; k < 4; k++){
                    int nx = i + dx[k], ny = j + dy[k];
                    if(0 <= nx && nx < N && 0 <= ny && ny < M && S[nx][ny] == '.'){
                        int t = nx * M + ny;
                        D.add(s, t, 1);
                    }
                }
            }
            else{
                int s = i * M + j, t = N * M + 1;
                D.add(s, t, 1);
            }
        }
    }
    int f = D.solve(N * M, N * M + 1);
    cout << f << endl;
    auto check = [&](int x, int y, int nx, int ny){
        if(x == nx && y + 1 == ny) S[x][y] = '>', S[nx][ny] = '<';
        else if(x == nx && y - 1 == ny) S[x][y] = '<', S[nx][ny] = '>';
        else if(x + 1 == nx && y == ny) S[x][y] = 'v', S[nx][ny] = '^';
        else if(x - 1 == nx && y == ny) S[x][y] = '^', S[nx][ny] = 'v';
    };
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(S[i][j] == '#') continue;
            if((i + j) % 2 == 1){
                for(edge e: D.G[i * M + j]){
                    if(e.to == N * M || e.to == N * M + 1) continue;
                    if(e.cap == 0){
                        int ny = e.to % M, nx = e.to / M;
                        check(i, j, nx, ny);
                    }
                }
            }
        }
    }
    for(int i = 0; i < N; i++) cout << S[i] << endl;
}

Compiler output:
a.cc: In member function 'void Dinic::add(int, int, long long int)':
a.cc:22:23: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
   22 |         edge e1 = {v, c, (int)G[v].size()};
      |                       ^
a.cc: In member function 'void Dinic::bfs(int)':
a.cc:29:9: error: 'queue' was not declared in this scope
   29 |         queue<int> q;
      |         ^~~~~
a.cc:3:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    2 | #include <vector>
  +++ |+#include <queue>
    3 | #include <string>
a.cc:29:15: error: expected primary-expression before 'int'
   29 |         queue<int> q;
      |               ^~~
a.cc:30:9: error: 'q' was not declared in this scope
   30 |         q.push(s);
      |         ^
a.cc: In member function 'long long int Dinic::dfs(int, int, long long int)':
a.cc:48:47: error: no matching function for call to 'min(long long int&, int&)'
   48 |                 long long d = dfs(e.to, t, min(f, e.cap));
      |                                            ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:48:47: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   48 |                 long long d = dfs(e.to, t, min(f, e.cap));
      |                                            ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided