Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repd(i, a, b) for (int i = (a); i > (b); i--)
#define forIt(it, a)                                                           \
  for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a)                                                          \
  for (__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define bitcount(n) __builtin_popcountll(n)
#define randchar() ((rand() % 26) + 'a')

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 1000 + 7;
const int M = 1000000;
const ll MM = 1ll * M * M;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = 0;

int n, m;
vi adj[N];
int depth[N];
int q[N], top;

void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i)
    depth[i] = -1;
  depth[1] = 0;
  q[top++] = 1;
  for (int i = 0; i < top; ++i) {
    int u = q[i];
    if (depth[u] >= 2)
      continue;
    for (int v : adj[u]) {
      if (depth[v] == -1) {
        depth[v] = depth[u] + 1;
        q[top++] = v;
      }
    }
  }
  //	for (int i = 1; i <= n; ++i) cout << i << ' ' << depth[i] << '\n';
  if (depth[n] != -1)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
}

int main() {
#ifdef _LOCAL_
  freopen("in.txt", "r", stdin);
  //	freopen("out.txt", "w", stdout);
#endif
  int Test = 1;
  if (multipleTest)
    cin >> Test;
  for (int i = 0; i < Test; ++i) {
    solve();
  }

#ifdef _LOCAL_
  cout << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repd(i, a, b) for (int i = (a); i > (b); i--)
#define forIt(it, a)                                                           \
  for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a)                                                          \
  for (__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define bitcount(n) __builtin_popcountll(n)
#define randchar() ((rand() % 26) + 'a')

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 200000 + 7;
const int M = 1000000;
const ll MM = 1ll * M * M;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = 0;

int n, m;
vi adj[N];
int depth[N];
int q[N], top;

void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i)
    depth[i] = -1;
  depth[1] = 0;
  q[top++] = 1;
  for (int i = 0; i < top; ++i) {
    int u = q[i];
    if (depth[u] >= 2)
      continue;
    for (int v : adj[u]) {
      if (depth[v] == -1) {
        depth[v] = depth[u] + 1;
        q[top++] = v;
      }
    }
  }
  //	for (int i = 1; i <= n; ++i) cout << i << ' ' << depth[i] << '\n';
  if (depth[n] != -1)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
}

int main() {
#ifdef _LOCAL_
  freopen("in.txt", "r", stdin);
  //	freopen("out.txt", "w", stdout);
#endif
  int Test = 1;
  if (multipleTest)
    cin >> Test;
  for (int i = 0; i < Test; ++i) {
    solve();
  }

#ifdef _LOCAL_
  cout << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
}