Language: C++

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;

using Weight = int;
using Capacity = int;
struct Edge {
	int src, dst; Capacity cap;
	Edge(int s, int d, Capacity c) : src(s), dst(d), cap(c) {}
};

struct Dinic {
public:
	using Flow = int;
	vector< vector<Edge> > g;
	Dinic(int n_) : n(n_), g(n_) {}
	Flow maximumFlow(int s_, int t_) {
		s = s_;
		t = t_;
		Flow res = 0;
		while(levelize()) {
			prog.assign(n, 0);
			res += augment(s, numeric_limits<Flow>::max());
		}
		return res;
	}
	void addEdge(int u, int v, Flow c) {
		g[u].push_back({ u, v, c, 0, (int)g[v].size() });
		g[v].push_back({ v, u, c, c, (int)g[u].size() - 1 });
	}

private:
	struct Edge { int s, d; Flow c, f; int r; };

	int n, s, t;
	vector<int> level, prog;
	queue<int> q;

	bool levelize() {
		q.push(s);
		level.assign(n, -1);
		level[s] = 0;
		while(q.size()) {
			int v = q.front();
			q.pop();
			if(v == t) break;
			for(auto &e : g[v]) {
				if(level[e.d] == -1 && residue(e) != 0) {
					level[e.d] = level[v] + 1;
					q.push(e.d);
				}
			}
		}
		return level[t] != -1;
	}
	Flow augment(int v, Flow lim) {
		Flow res = 0;
		if(v == t) return lim;
		for(int &i = prog[v]; i < (int)g[v].size(); ++i) {
			if(lim == 0) break;
			auto &e = g[v][i];
			if(level[v] < level[e.d] && residue(e) != 0) {
				Flow aug = augment(e.d, min(lim, residue(e)));
				e.f += aug;
				reverse(e).f -= aug;
				res += aug;
				lim -= aug;
			}
		}
		return res;
	}
	Flow residue(const Edge& e) { return e.c - e.f; }
	Edge &reverse(const Edge &e) { return g[e.d][e.r]; }
};

int W, H;
int toV(int i, int j) {
	return W * i + j;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	Dinic dinic(20 * 20 + 2);

	int Test;
	cin >> Test;
	for(int t = 1; t <= Test; t++) {
		cin >> W >> H;
		int r[20][20];
		int sum = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> r[i][j];
				sum += r[i][j];
			}
		}

		for(int i = 0; i < H * W + 2; i++) {
			dinic.g[i].clear();
		}

		int S = H * W, T = S + 1;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if((i + j) % 2 == 0) {
					dinic.addEdge(S, toV(i, j), r[i][j]);
					dinic.addEdge(toV(i, j), T, 0);
					for(int k = 0; k < 4; k++) {
						int ni = i + dy[k], nj = j + dx[k];
						if(ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
						dinic.addEdge(toV(i, j), toV(ni, nj), 1e9);
					}
				}
				else {
					dinic.addEdge(S, toV(i, j), 0);
					dinic.addEdge(toV(i, j), T, r[i][j]);
				}
			}
		}

		cout << "Case " << t << ": " << sum - dinic.maximumFlow(S, T) << endl;
	}

}

Compiler output:
a.cc:40:16: error: declaration of 'struct Dinic::Edge' changes meaning of 'Edge' [-Wchanges-meaning]
   40 |         struct Edge { int s, d; Flow c, f; int r; };
      |                ^~~~
a.cc:22:24: note: used here to mean 'struct Edge'
   22 |         vector< vector<Edge> > g;
      |                        ^~~~
a.cc:14:8: note: declared here
   14 | struct Edge {
      |        ^~~~
a.cc: In member function 'void Dinic::addEdge(int, int, Flow)':
a.cc:35:31: error: no matching function for call to 'std::vector<Edge>::push_back(<brace-enclosed initializer list>)'
   35 |                 g[u].push_back({ u, v, c, 0, (int)g[v].size() });
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Edge; _Alloc = std::allocator<Edge>; value_type = Edge]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<Edge>::value_type&' {aka 'const Edge&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = Edge; _Alloc = std::allocator<Edge>; value_type = Edge]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<Edge>::value_type&&' {aka 'Edge&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:36:31: error: no matching function for call to 'std::vector<Edge>::push_back(<brace-enclosed initializer list>)'
   36 |                 g[v].push_back({ v, u, c, c, (int)g[u].size() - 1 });
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Edge; _Alloc = std::allocator<Edge>; value_type = Edge]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<Edge>::value_type&' {aka 'const Edge&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = Edge; _Alloc = std::allocator<Edge>; value_type = Edge]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<Edge>::value_type&&' {aka 'Edge&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc: In member function 'bool Dinic::levelize()':
a.cc:55:44: error: 'struct Edge' has no member named 'd'
   55 |                                 if(level[e.d] == -1 && residue(e) != 0) {
      |                                            ^
a.cc:55:64: error: cannot convert 'Edge' to 'const Dinic::Edge&'
   55 |                                 if(level[e.d] == -1 && residue(e) != 0) {
      |                                                                ^
      |                                                                |
      |                                                                Edge
a.cc:79:34: note:   initializing argument 1 of 'Dinic::Flow Dinic::residue(const Edge&)'
   79 |         Flow residue(const Edge& e) { return e.c - e.f; }
      |                      ~~~~~~~~~~~~^
a.cc:56:49: error: 'struct Edge' has no member named 'd'
   56 |                                         level[e.d] = level[v] + 1;
      |                                                 ^
a.cc:57:50: error: 'struct Edge' has no member named 'd'
   57 |                                         q.push(e.d);
      |                                                  ^
a.cc: In member function 'Dinic::Flow Dinic::augment(int, Flow)':
a.cc:69:47: error: 'struct Edge' has no member named 'd'
   69 |                         if(level[v] < level[e.d] && residue(e) != 0) {
      |                                               ^
a.cc:69:61: error: cannot convert 'Edge' to 'const Dinic::Edge&'
   69 |                         if(level[v] < level[e.d] && residue(e) != 0) {
      |                                                             ^
      |                                                             |
      |                                                             Edge
a.cc:79:34: note:   initializing argument 1 of 'Dinic::Flow Dinic::residue(const Edge&)'
   79 |         Flow residue(const Edge& e) { return e.c - e.f; }
      |                      ~~~~~~~~~~~~^
a.cc:70:54: error: 'struct Edge' has no member named 'd'
   70 |                                 Flow aug = augment(e.d, min(lim, residue(e)));
      |                                                      ^
a.cc:70:74: error: cannot convert 'Edge' to 'const Dinic::Edge&'
   70 |                                 Flow aug = augment(e.d, min(lim, residue(e)));
      |                                                                          ^
      |                                                                          |
      |                                                                          Edge
a.cc:79:34: note:   initializing argument 1 of 'Dinic::Flow Dinic::residue(const Edge&)'
   79 |         Flow residue(const Edge& e) { return e.c - e.f; }
      |                      ~~~~~~~~~~~~^
a.cc:71:35: error: 'struct Edge' has no member named 'f'
   71 |                                 e.f += aug;
      |                                   ^
a.cc:72:41: error: cannot convert 'Edge' to 'const Dinic::Edge&'
   72 |                                 reverse(e).f -= aug;
      |                                         ^
      |                                         |
      |                                         Edge
a.cc:80:35: note:   initializing argument 1 of 'Dinic::Edge& Dinic::reverse(const Edge&)'
   80 |         Edge &reverse(const Edge &e) { return g[e.d][e.r]; }
      |                       ~~~~~~~~~~~~^
a.cc: In member function 'Dinic::Edge& Dinic::reverse(const Edge&)':
a.cc:80:57: error: invalid initialization of reference of type 'Dinic::Edge&' from expression of type '__gnu_cxx::__alloc_traits<std::allocator<Edge>, Edge>::value_type' {aka 'Edge'}
   80 |         Edge &reverse(const Edge &e) { return g[e.d][e.r]; }
      |                                                         ^