Problem p03647 (C++)

Buggy submission (status: Runtime Error):
// ITNOA
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define scan(x)                                                                \
  do {                                                                         \
    while ((x = getchar()) < '0')                                              \
      ;                                                                        \
    for (x -= '0'; '0' <= (_ = getchar()); x = (x << 3) + (x << 1) + _ - '0')  \
      ;                                                                        \
  } while (0)
char _;

#define rep(i, s, e) for (int i = s; i < e; i++)
#define int long long
#define X first
#define Y second

typedef long long ll;
typedef long double ld;

const int maxN = 300 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 500;
const int maxL = 20;

vector<int> a[maxN];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> v >> u;
    v--;
    u--;
    a[v].push_back(u);
    a[u].push_back(v);
  }

  for (int i = 1; i < n - 1; i++) {
    bool f1 = 0, fn = 0;
    for (int j = 0; j < a[i].size(); j++) {
      if (a[i][j] == 0)
        f1 = true;
      if (a[i][j] == n - 1)
        fn = true;
    }
    if (f1 && fn) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Fixed submission:
// ITNOA
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define scan(x)                                                                \
  do {                                                                         \
    while ((x = getchar()) < '0')                                              \
      ;                                                                        \
    for (x -= '0'; '0' <= (_ = getchar()); x = (x << 3) + (x << 1) + _ - '0')  \
      ;                                                                        \
  } while (0)
char _;

#define rep(i, s, e) for (int i = s; i < e; i++)
#define int long long
#define X first
#define Y second

typedef long long ll;
typedef long double ld;

const int maxN = 200 * 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 500;
const int maxL = 20;

vector<int> a[maxN];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> v >> u;
    v--;
    u--;
    a[v].push_back(u);
    a[u].push_back(v);
  }

  for (int i = 1; i < n - 1; i++) {
    bool f1 = 0, fn = 0;
    for (int j = 0; j < a[i].size(); j++) {
      if (a[i][j] == 0)
        f1 = true;
      if (a[i][j] == n - 1)
        fn = true;
    }
    if (f1 && fn) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
  return 0;
}