#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int MAX_M = 101;
const int INF = 0x3f3f3f3f;
struct Node {
int x, y, s;
int cost;
bool operator<(const Node& other) const {
return cost > other.cost; // 小顶堆
}
};
int board[MAX_M][MAX_M];
int dist[MAX_M][MAX_M]; // s: 0(未用魔法),1(魔法颜色0),2(魔法颜色1)
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int main() {
int m, n;
cin >> m >> n;
memset(board, -1, sizeof(board));
for (int i = 0; i < n; ++i) {
int x, y, c;
cin >> x >> y >> c;
board[x][y] = c;
}
memset(dist, 0x3f, sizeof(dist));
dist = 0;
priority_queue<Node> pq;
pq.push({1, 1, 0, 0});
while (!pq.empty()) {
Node node = pq.top();
pq.pop();
int x = node.x, y = node.y, s = node.s, cost = node.cost;
if (cost > dist[x][y][s]) continue;
if (x == m && y == m) continue;
for (int i = 0; i < 4; ++i) {
int nx
/**************************************************************
Problem: 1483
User: caijiajie
Language: C++
Result: Compile Error
****************************************************************/