Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr int INF = 1e9;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

// #####################
// Dijkstra
// #####################
struct edge {
  int to, cost;
};

int n, m;
vector<edge> g[112345];
int dis[112345];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(dis, dis + n + 1, INF);
  dis[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int n_ = p.second;
    if (dis[n_] < p.first)
      continue;
    for (int i = 0; i < g[n_].size(); i++) {
      edge e = g[n_][i];
      if (dis[e.to] > dis[n_] + e.cost) {
        dis[e.to] = dis[n_] + e.cost;
        que.push(P(dis[e.to], e.to));
      }
    }
  }
}

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

  cin >> n >> m;

  REP(i, m) {
    int a, b;
    cin >> a >> b;

    g[a].push_back({b, 1});
    g[b].push_back({a, 1});
  }

  dijkstra(1);

  if (dis[n] == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr int INF = 1e9;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

// #####################
// Dijkstra
// #####################
struct edge {
  int to, cost;
};

int n, m;
vector<edge> g[212345];
int dis[212345];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(dis, dis + n + 1, INF);
  dis[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int n_ = p.second;
    if (dis[n_] < p.first)
      continue;
    for (int i = 0; i < g[n_].size(); i++) {
      edge e = g[n_][i];
      if (dis[e.to] > dis[n_] + e.cost) {
        dis[e.to] = dis[n_] + e.cost;
        que.push(P(dis[e.to], e.to));
      }
    }
  }
}

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

  cin >> n >> m;

  REP(i, m) {
    int a, b;
    cin >> a >> b;

    g[a].push_back({b, 1});
    g[b].push_back({a, 1});
  }

  dijkstra(1);

  if (dis[n] == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}