Language: C++

#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

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

struct node {
	int x, y, d;
	node(int x, int y, int d):x(x), y(y), d(d) {}

	bool operator>(const node& o) const {
		return d > o.d;
	}
};

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

	int w, h;
	cin >> w >> h;

	vector<string> field(h);
	for(int i = 0; i < h; ++i)
		cin >> field[i];

	int gx, gy;
	vector<vector<int> > label(h, vector<int>(w, 0));
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(field[i][j] == '#')
				label[i][j] = INT_MAX;

			else if(field[i][j] == 't') {
				gx = j;
				gy = i;
			}
		}
	}

	int n;
	cin >> n;

	for(int i = 1; i <= n; ++i) {
		int x, y;
		cin >> x >> y;
		chmin(label[y][x], i);
	}

	vector<vector<int> > dist(h, vector<int>(w, INT_MAX));
	dist[0][0] = 0;

	priority_queue<node, vector<node>, greater<node> > que;
	que.push(node(0, 0, 0));

	while(!que.empty()) {
		node n = que.top();
		que.pop();

		for(int i = 0; i < 4; ++i) {
			int x = n.x + dx[i];
			int y = n.y + dy[i];

			if(x < 0 || y < 0 || x >= w || y >= h || dist[y][x] == label[y][x])
				continue;

			if(dist[y][x] > max(n.d, label[y][x])) {
				dist[y][x] = max(n.d, label[y][x]);
				que.push(node(x, y, dist[y][x]));
			}
				
		}
	}

	cout << (dist[gy][gx] == INT_MAX ? -1 : dist[gy][gx]) << endl;

	return EXIT_SUCCESS;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:16: error: no matching function for call to 'std::basic_istream<char>::tie(bool)'
   24 |         cin.tie(false);
      |         ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/c++/14/bits/basic_ios.h:299:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie() const [with _CharT = char; _Traits = std::char_traits<char>]'
  299 |       tie() const
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:299:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/basic_ios.h:311:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie(std::basic_ostream<_CharT, _Traits>*) [with _CharT = char; _Traits = std::char_traits<char>]'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:311:43: note:   no known conversion for argument 1 from 'bool' to 'std::basic_ostream<char>*'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
a.cc:39:47: error: 'INT_MAX' was not declared in this scope
   39 |                                 label[i][j] = INT_MAX;
      |                                               ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include <queue>
  +++ |+#include <climits>
    5 | #include <string>
a.cc:57:53: error: 'INT_MAX' was not declared in this scope
   57 |         vector<vector<int> > dist(h, vector<int>(w, INT_MAX));
      |                                                     ^~~~~~~
a.cc:57:53: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'