Language: C++

#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

const int N = 100000;

int n;
int m;
vector<pair<ii, int> > v;
ll row[N];
ll col[N];
int setrow[N];
int setcol[N];
int wasrow[N];
int wascol[N];
int needrow[N];
int needcol[N];
vi urow, ucol;
vii vrow[N];
vii vcol[N];
ll cor;
int setcor;
int q;
vector<pair<ll, ll> > w;

int gocol (int x, ll y);

int gorow (int x, ll y) {
//	cerr << x << " " << y << endl;
	if (wasrow[x] && row[x] != y) re 0;
	if (wasrow[x]) re 1;
	urow.pb (x);
	wasrow[x] = 1;
	row[x] = y;
	for (int i = 0; i < sz (vrow[x]); i++)
		if (!gocol (vrow[x][i].fi, vrow[x][i].se - y))
			re 0;
	re 1;
}

int gocol (int x, ll y) {
//	cerr << x << " " << y << endl;
	if (wascol[x] && col[x] != y) re 0;
	if (wascol[x]) re 1;
	ucol.pb (x);
	wascol[x] = 1;
	col[x] = y;
	for (int i = 0; i < sz (vcol[x]); i++)
		if (!gorow (vcol[x][i].fi, vcol[x][i].se - y))
			re 0;
	re 1;
}

int main () {
	scanf ("%d%d%d", &n, &m, &q);
	for (int i = 0; i < q; i++) {
		int a, b, c;
		scanf ("%d%d%d", &a, &b, &c); a--; b--;
		if (a == 0 && b == 0) { setcor = 1; cor = c; } else
		if (a == 0) { setcol[b] = 1; needcol[b] = c; } else
		if (b == 0) { setrow[a] = 1; needrow[a] = c; } else {
			vrow[a].pb (mp (b, c));
			vcol[b].pb (mp (a, c));
		}
	}
	for (int i = 1; i < n; i++)
		if (!wasrow[i] && setrow[i]) {
			urow.clear ();
			ucol.clear ();
			if (!gorow (i, needrow[i])) {
				printf ("No\n");
				re 0;
			}
			for (int j = 0; j < sz (urow); j++) {
				int k = urow[j];
				if (setrow[k] && needrow[k] != row[k]) {
					printf ("No\n");
					re 0;
				}
			}
			for (int j = 0; j < sz (ucol); j++) {
				int k = ucol[j];
				if (setcol[k]) {
					if (setcor) {
						if (needcol[k] != col[k] + cor) {
							printf ("No\n");
							re 0;
						}
					} else {
						setcor = 1;
						cor = needcol[k] - col[k];
					}
				}
			}
			ll minrow = 1e18, mincol = 1e18;
			for (int j = 0; j < sz (urow); j++)
				minrow = min (minrow, row[urow[j]]);
			for (int j = 0; j < sz (ucol); j++)
				mincol = min (mincol, col[ucol[j]]);
			w.pb (mp (minrow, mincol));
		}
	for (int i = 1; i < m; i++)
		if (!wascol[i] && setcol[i]) {
			urow.clear ();
			ucol.clear ();
			if (!gocol (i, col[i])) {
				printf ("No\n");
				re 0;
			}
			for (int j = 0; j < sz (ucol); j++) {
				int k = ucol[j];
				if (setcol[k] && needcol[k] != col[k]) {
					printf ("No\n");
					re 0;
				}
			}	
			for (int j = 0; j < sz (urow); j++) {
				int k = urow[j];
				if (setrow[k]) {
					if (setcor) {
						if (needrow[k] != row[k] + cor) {
							printf ("No\n");
							re 0;
						}							
					} else {
						setcor = 1;
						cor = needrow[k] - row[k];
					}
				}
			}
			ll minrow = 1e18, mincol = 1e18;
			for (int j = 0; j < sz (urow); j++)
				minrow = min (minrow, row[urow[j]]);
			for (int j = 0; j < sz (ucol); j++)
				mincol = min (mincol, col[ucol[j]]);
			w.pb (mp (mincol, minrow));
		}
	for (int i = 1; i < n; i++)
		if (!wasrow[i]) {
			urow.clear ();
			ucol.clear ();
			if (!gorow (i, 0)) {
				printf ("No\n");
				re 0;
			}
			ll minrow = 1e18, mincol = 1e18;
			for (int j = 0; j < sz (urow); j++)
				minrow = min (minrow, row[urow[j]]);
			for (int j = 0; j < sz (ucol); j++)
				mincol = min (mincol, col[ucol[j]]);
			w.pb (mp (minrow, mincol));
		}
	for (int i = 1; i < m; i++)
		if (!wascol[i]) {
			urow.clear ();
			ucol.clear ();
			if (!gocol (i, 0)) {
				printf ("No\n");
				re 0;
			}
			ll minrow = 1e18, mincol = 1e18;
			for (int j = 0; j < sz (urow); j++)
				minrow = min (minrow, row[urow[j]]);
			for (int j = 0; j < sz (ucol); j++)
				mincol = min (mincol, col[ucol[j]]);
			w.pb (mp (minrow, mincol));
		}
	if (setcor && cor < 0) {
		printf ("No\n");
		re 0;
	}
	if (setcor) {
		for (int i = 0; i < sz (w); i++) {
			w[i].se += cor;
			if (w[i].fi < 0 || w[i].se < 0) {
				printf ("No\n");
				re 0;
			}
		}	
	} else {
		for (int i = 0; i < sz (w); i++)
			if (w[i].fi + w[i].se < 0) {
				printf ("No\n");
				re 0;
			}
		}
	}
	printf ("Yes\n");	
	return 0;
}

Compiler output:
a.cc:231:16: error: expected constructor, destructor, or type conversion before '(' token
  231 |         printf ("Yes\n");
      |                ^
a.cc:232:9: error: expected unqualified-id before 'return'
  232 |         return 0;
      |         ^~~~~~
a.cc:233:1: error: expected declaration before '}' token
  233 | }
      | ^