Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility> // std::swap
#include <vector>
typedef long long int ll;
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < signed(n); i++)
#define EREP(i, n) for (int i = 1; i <= (n); i++)
#define ALL(a) (a).begin(), (a).end()
// #define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" << X << " ";
#define TF(f) f ? cout << "true  " : cout << "false ";
#define END cout << "\n";
#else
#define DEB(X)                                                                 \
  {}
#define TF(f)                                                                  \
  {}
#define END                                                                    \
  {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;
struct edge {
  int to, cost;
};
typedef std::pair<int, int> P;
ll W, H, N, M;
ll sum = 0;
// ll A[300000],B[300000];
ll d[300000];
ll back = 0;
bool f = false;
ll ans = INF;
vector<edge> G[100001];

void dijkstra(int s) {
  std::priority_queue<P, vector<P>, std::greater<P>> que;
  std::fill(d, d + N, INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {

    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < (signed)G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    edge es;
    es.to = b - 1, es.cost = 1;
    G[a - 1].push_back(es);
    es.to = a - 1;
    G[b - 1].push_back(es);
  }
  dijkstra(0);
  if (d[N - 1] == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility> // std::swap
#include <vector>
typedef long long int ll;
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < signed(n); i++)
#define EREP(i, n) for (int i = 1; i <= (n); i++)
#define ALL(a) (a).begin(), (a).end()
// #define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" << X << " ";
#define TF(f) f ? cout << "true  " : cout << "false ";
#define END cout << "\n";
#else
#define DEB(X)                                                                 \
  {}
#define TF(f)                                                                  \
  {}
#define END                                                                    \
  {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;
struct edge {
  int to, cost;
};
typedef std::pair<int, int> P;
ll W, H, N, M;
ll sum = 0;
// ll A[300000],B[300000];
ll d[300000];
ll back = 0;
bool f = false;
ll ans = INF;
vector<edge> G[300001];

void dijkstra(int s) {
  std::priority_queue<P, vector<P>, std::greater<P>> que;
  std::fill(d, d + N, INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {

    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < (signed)G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    edge es;
    es.to = b - 1, es.cost = 1;
    G[a - 1].push_back(es);
    es.to = a - 1;
    G[b - 1].push_back(es);
  }
  dijkstra(0);
  if (d[N - 1] == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}