message: Update swim-in-rising-water.cpp
diff: class Solution {
  public:
  int swimInWater(vector<vector<int>>& grid) {
  - const int m = grid.size(), n = grid[0].size();
  - vector<pair<int, int>> positions(m * n);
  - for (int i = 0; i < m; ++i) {
  + const int n = grid.size();
  + vector<pair<int, int>> positions(n * n);
  + for (int i = 0; i < n; ++i) {
  for (int j = 0; j < n; ++j) {
  positions[grid[i][j]] = {i, j};
  }
  }
  static const vector<pair<int, int>> directions{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  - UnionFind union_find(m * n);
  + UnionFind union_find(n * n);
  for (int elevation = 0; elevation < positions.size(); ++elevation) {
  int i, j;
  tie(i, j) = positions[elevation];
  for (const auto& dir : directions) {
  int x = i + dir.first;
  int y = j + dir.second;
  - if (0 <= x && x < m &&
  + if (0 <= x && x < n &&
  0 <= y && y < n &&
  grid[x][y] <= elevation) {
  union_find.union_set(i * n + j, x * n + y);
  - if (union_find.find_set(0) == union_find.find_set(m * n - 1)) {
  + if (union_find.find_set(0) == union_find.find_set(n * n - 1)) {
  return elevation;
  }
  }
  }
  }
  - return m * n - 1;
  + return n * n - 1;
  }
  private:
  