Problem p03647 (C++)

Buggy submission (status: Runtime Error):
// #include "IntMod.h"
// typedef IntMod<1000000007> MInt;

// #include "Union_Find.h"

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPM(i, n, a) for (int i = ((n)-1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream &operator>>(istream &ist, pair<T, U> &right) {
  return ist >> right.first >> right.second;
}
template <class T, class U>
ostream &operator<<(ostream &ost, pair<T, U> &right) {
  return ost << right.first << ' ' << right.second;
}
template <class T, class TCompatible, size_t N>
void Fill(T (&dest)[N], const TCompatible &val) {
  fill(begin(dest), end(dest), val);
}
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T (&dest)[M][N], const TCompatible &val) {
  for (int i = 0; i < M; ++i)
    Fill(dest[i], val);
}

#if 1
#include <unordered_map>
#include <unordered_set>
template <typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T>>; // コスト小を優先
#endif

int N, M;
int A[100000];
int main() {
  cin >> N >> M;
  REP(i, 0, M) {
    int a, b;
    cin >> a >> b;
    if (a > b)
      swap(a, b);
    if (a == 1)
      A[b] |= 1;
    if (b == N)
      A[a] |= 2;
  }
  cout << (find(A, A + N, 3) == A + N ? "IM" : "") << "POSSIBLE" << endl;
  return 0;
}

Fixed submission:
// #include "IntMod.h"
// typedef IntMod<1000000007> MInt;

// #include "Union_Find.h"

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPM(i, n, a) for (int i = ((n)-1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream &operator>>(istream &ist, pair<T, U> &right) {
  return ist >> right.first >> right.second;
}
template <class T, class U>
ostream &operator<<(ostream &ost, pair<T, U> &right) {
  return ost << right.first << ' ' << right.second;
}
template <class T, class TCompatible, size_t N>
void Fill(T (&dest)[N], const TCompatible &val) {
  fill(begin(dest), end(dest), val);
}
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T (&dest)[M][N], const TCompatible &val) {
  for (int i = 0; i < M; ++i)
    Fill(dest[i], val);
}

#if 1
#include <unordered_map>
#include <unordered_set>
template <typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T>>; // コスト小を優先
#endif

int N, M;
int A[200000];
int main() {
  cin >> N >> M;
  REP(i, 0, M) {
    int a, b;
    cin >> a >> b;
    if (a > b)
      swap(a, b);
    if (a == 1)
      A[b] |= 1;
    if (b == N)
      A[a] |= 2;
  }
  cout << (find(A, A + N, 3) == A + N ? "IM" : "") << "POSSIBLE" << endl;
  return 0;
}