prithivMLmods/Coder-Stat huggingface dataset:
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <class T> inline T LCM(T a, T b) { return a / GCD(a, b) * b; }

int main() {
  vector<ll> g[200010];
  ll n, m;
  cin >> n >> m;
  ll a[200010], b[200010];
  FOR(i, m) {
    cin >> a[i] >> b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  vector<ll> v;

  FOR(i, g[1].size()) { v.push_back(g[1][i]); }
  vector<ll> h;
  FOR(j, g[n].size()) { h.push_back(g[n][j]); }
  sort(all(h));
  FOR(i, v.size()) {
    auto itr = lower_bound(all(h), v[i]);
    if (*itr == v[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <class T> inline T LCM(T a, T b) { return a / GCD(a, b) * b; }

int main() {
  vector<ll> g[200010];
  ll n, m;
  cin >> n >> m;
  ll a[200010], b[200010];
  FOR(i, m) {
    cin >> a[i] >> b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  vector<ll> v;

  FOR(i, g[1].size()) { v.push_back(g[1][i]); }
  vector<ll> h;
  FOR(j, g[n].size()) { h.push_back(g[n][j]); }
  h.push_back(0);
  h.push_back(1000000000000);
  sort(all(h));
  FOR(i, v.size()) {
    auto itr = lower_bound(all(h), v[i]);
    if (*itr == v[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
}
Problem p03647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  set<int> a;
  vector<pair<int, int>> b;
  vector<int> from(m), to(m);
  for (int i = 0; i < m; i++) {
    cin >> from[i] >> to[i];
    if (from[i] == 1)
      a.insert(to[i]);
    if (from[i] != 1 && to[i] == n)
      b.push_back(make_pair(from[i], to[i]));
  }
  for (auto value : a) {
    for (int i = 0; i < b.size(); i++) {
      if (value == b[i].first && b[i].second == n) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  set<int> a;
  vector<pair<int, int>> b;
  vector<int> from(m), to(m);
  for (int i = 0; i < m; i++) {
    cin >> from[i] >> to[i];
    if (from[i] == 1)
      a.insert(to[i]);
    if (from[i] != 1 && to[i] == n)
      b.push_back(make_pair(from[i], to[i]));
  }
  for (int i = 0; i < b.size(); i++) {
    if (a.count(b[i].first)) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> g[101010];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> ans;
  for (int i = 0; i < g[0].size(); i++) {
    ans.push_back(g[0][i]);
  }
  bool ok = false;
  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j < g[ans[i]].size(); j++) {
      if (g[ans[i]][j] == n - 1) {
        ok = true;
        break;
      }
    }
  }
  cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> g[202020];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> ans;
  for (int i = 0; i < g[0].size(); i++) {
    ans.push_back(g[0][i]);
  }
  bool ok = false;
  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j < g[ans[i]].size(); j++) {
      if (g[ans[i]][j] == n - 1) {
        ok = true;
        break;
      }
    }
  }
  cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
set<int> go[100005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    go[x].insert(y);
  }
  for (set<int>::iterator it = go[1].begin(); it != go[1].end(); it++) {
    int num = *it;
    if (go[num].find(n) != go[num].end()) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
set<int> go[200005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    go[x].insert(y);
  }
  for (set<int>::iterator it = go[1].begin(); it != go[1].end(); it++) {
    int num = *it;
    if (go[num].find(n) != go[num].end()) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, N) FOR(i, 0, N)
#define SZ(x) ((int)(x).size())

const int MAXN = 100007, INF = 100000007;

int main() {
  int N, M, a, b, d[MAXN];
  vector<int> G[MAXN];
  queue<int> Q;
  scanf("%d%d", &N, &M);
  REP(i, M) {
    scanf("%d%d", &a, &b);
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  d[0] = 0;
  Q.push(0);
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    if (d[v] < 2)
      REP(i, SZ(G[v])) {
        int to = G[v][i];
        if (to != 0)
          Q.push(to);
        d[to] = d[v] + 1;
      }
  }
  if (d[N - 1] != 2)
    printf("IM");
  printf("POSSIBLE");
  // cout << endl; system("pause");//please
  return 0;
} // don't forget about const, please
/*
4
0 3 1 1
6 0 400 1
2 4 0 1
1 1 1 0
4 1 2 3
fictive
*/

Fixed submission:
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, N) FOR(i, 0, N)
#define SZ(x) ((int)(x).size())

const int MAXN = 200007, INF = 100000007;

int main() {
  int N, M, a, b, d[MAXN];
  vector<int> G[MAXN];
  queue<int> Q;
  scanf("%d%d", &N, &M);
  REP(i, M) {
    scanf("%d%d", &a, &b);
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  d[0] = 0;
  Q.push(0);
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    if (d[v] < 2)
      REP(i, SZ(G[v])) {
        int to = G[v][i];
        if (to != 0)
          Q.push(to);
        d[to] = d[v] + 1;
      }
  }
  if (d[N - 1] != 2)
    printf("IM");
  printf("POSSIBLE");
  // cout << endl; system("pause");//please
  return 0;
} // don't forget about const, please
/*
4
0 3 1 1
6 0 400 1
2 4 0 1
1 1 1 0
4 1 2 3
fictive
*/
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (int i = (ll)(r); i < (ll)(n); i++)
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
// vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge {
  int from, to;
  Weight cost;
  bool operator<(const Edge &e) const { return cost < e.cost; }
  bool operator>(const Edge &e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost) {
  g[from].push_back(Edge{from, to, cost});
}

int main() {
  ll n, m;
  cin >> n >> m;
  Graph g(n);
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    add_edge(g, a - 1, b - 1, 1);
    add_edge(g, b - 1, a - 1, 1);
  }
  if (m == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  FOR(i, 1, n - 1) {
    if (g[0][i].cost && g[i][n - 1].cost) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (int i = (ll)(r); i < (ll)(n); i++)
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
// vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge {
  int from, to;
  Weight cost;
  bool operator<(const Edge &e) const { return cost < e.cost; }
  bool operator>(const Edge &e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost) {
  g[from].push_back(Edge{from, to, cost});
}

int main() {
  ll n, m;
  cin >> n >> m;
  Graph g(n);
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    add_edge(g, a - 1, b - 1, 1);
    add_edge(g, b - 1, a - 1, 1);
  }
  if (m == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  for (auto e : g[0]) {
    if (e.cost) {
      ll dest = e.to;
      for (auto tmp : g[dest]) {
        if (tmp.cost && tmp.to == n - 1) {
          cout << "POSSIBLE" << endl;
          return 0;
        }
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int n;
vector<vector<int>> to;
bool flag = 0;
void dfs(int v, int p = -1, int d = 0) {
  rep(i, to[v].size()) {
    int nv = to[v][i];
    if (nv == p)
      continue;
    if (d == 1 && nv != n - 1)
      continue;
    if (nv == n - 1)
      flag = 1;
    dfs(nv, v, d + 1);
  }
}

int main() {
  int m;
  cin >> n >> m;
  to.resize(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int n;
vector<vector<int>> to;
bool flag = 0;
void dfs(int v, int p = -1, int d = 0) {
  rep(i, to[v].size()) {
    int nv = to[v][i];
    if (nv == p)
      continue;
    if (d == 1 && nv != n - 1)
      continue;
    if (nv == n - 1)
      flag = 1;
    if (!flag)
      dfs(nv, v, d + 1);
  }
}

int main() {
  int m;
  cin >> n >> m;
  to.resize(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 4;
const int inf = 0x3f3f3f3f;
int n, m;
vector<int> G[maxn];
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bool flag = false;
  for (int i = 0; i < G[1].size(); i++) {
    u = G[1][i];
    for (int j = 0; j < G[u].size(); j++) {
      v = G[u][j];
      if (v == n) {
        flag = true;
        break;
      }
    }
    if (flag)
      break;
  }
  if (flag)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 4;
const int inf = 0x3f3f3f3f;
int n, m;
vector<int> G[maxn];
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bool flag = false;
  for (int i = 0; i < G[1].size(); i++) {
    u = G[1][i];
    for (int j = 0; j < G[u].size(); j++) {
      v = G[u][j];
      if (v == n) {
        flag = true;
        break;
      }
    }
    if (flag)
      break;
  }
  if (flag)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int N, M, Ai, Bi;
queue<pair<int, int>> Q;
int dist[20005];
vector<int> G[20005];

int main() {

  cin >> N >> M;
  while (M--) {
    cin >> Ai >> Bi;
    G[Ai].push_back(Bi);
    G[Bi].push_back(Ai);
  }

  int SAUCE = 1;
  memset(dist, -1, sizeof(dist));
  Q.push(make_pair(0, SAUCE));
  while (!Q.empty()) {
    int d = Q.front().first, u = Q.front().second;
    Q.pop();
    if (dist[u] != -1)
      continue;
    dist[u] = d;
    for (int i = 0; i < G[u].size(); i++) {
      Q.push(make_pair(d + 1, G[u][i]));
    }
  }

  if (dist[N] == 2) {
    cout << "POSSIBLE\n";
  } else {
    cout << "IMPOSSIBLE\n";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int N, M, Ai, Bi;
queue<pair<int, int>> Q;
int dist[200005];
vector<int> G[200005];

int main() {

  cin >> N >> M;
  while (M--) {
    cin >> Ai >> Bi;
    G[Ai].push_back(Bi);
    G[Bi].push_back(Ai);
  }

  int SAUCE = 1;
  memset(dist, -1, sizeof(dist));
  Q.push(make_pair(0, SAUCE));
  while (!Q.empty()) {
    int d = Q.front().first, u = Q.front().second;
    Q.pop();
    if (dist[u] != -1)
      continue;
    dist[u] = d;
    for (int i = 0; i < G[u].size(); i++) {
      Q.push(make_pair(d + 1, G[u][i]));
    }
  }

  if (dist[N] == 2) {
    cout << "POSSIBLE\n";
  } else {
    cout << "IMPOSSIBLE\n";
  }
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;

const int Maxn = 10000;

int main() {
  int n, m, vis[Maxn];
  while (~scanf("%d %d", &n, &m) && n) {
    int flag = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      if (flag)
        continue;
      if (u == 1) {
        if (vis[v])
          flag = 1;
        else
          vis[v] = 1;
      } else if (v == 1) {
        if (vis[u])
          flag = 1;
        else
          vis[u] = 1;
      } else if (v == n) {
        if (vis[u])
          flag = 1;
        else
          vis[u] = 1;
      } else if (u == n) {
        if (vis[v])
          flag = 1;
        else
          vis[v] = 1;
      }
    }
    if (flag)
      printf("POSSIBLE\n");
    else
      printf("IMPOSSIBLE\n");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;

const int Maxn = 200000;

int main() {
  int n, m, vis[Maxn];
  while (~scanf("%d %d", &n, &m) && n) {
    int flag = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      if (flag)
        continue;
      if (u == 1) {
        if (vis[v])
          flag = 1;
        else
          vis[v] = 1;
      } else if (v == 1) {
        if (vis[u])
          flag = 1;
        else
          vis[u] = 1;
      } else if (v == n) {
        if (vis[u])
          flag = 1;
        else
          vis[u] = 1;
      } else if (u == n) {
        if (vis[v])
          flag = 1;
        else
          vis[v] = 1;
      }
    }
    if (flag)
      printf("POSSIBLE\n");
    else
      printf("IMPOSSIBLE\n");
  }
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  rep(i, m) { cin >> a.at(i) >> b.at(i); }
  vector<int> c;
  vector<int> d;
  rep(i, n) {
    if (a.at(i) == 1)
      c.pb(b.at(i));
    if (b.at(i) == n)
      d.pb(a.at(i));
  }
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  int i = 0, j = 0;
  while (i < c.size() && j < d.size()) {
    if (c.at(i) == d.at(j)) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    if (c.at(i) < d.at(j)) {
      if (i >= c.size() - 1) {
        if (j >= d.size() - 1)
          break;
        j++;
      } else {
        i++;
      }
    } else {
      if (j >= d.size() - 1) {
        if (i >= c.size() - 1)
          break;
        i++;
      } else {
        j++;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  rep(i, m) { cin >> a.at(i) >> b.at(i); }
  vector<int> c;
  vector<int> d;
  rep(i, m) {
    if (a.at(i) == 1)
      c.pb(b.at(i));
    if (b.at(i) == n)
      d.pb(a.at(i));
  }
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  int i = 0, j = 0;
  while (i < c.size() && j < d.size()) {
    if (c.at(i) == d.at(j)) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    if (c.at(i) < d.at(j)) {
      if (i >= c.size() - 1) {
        if (j >= d.size() - 1)
          break;
        j++;
      } else {
        i++;
      }
    } else {
      if (j >= d.size() - 1) {
        if (i >= c.size() - 1)
          break;
        i++;
      } else {
        j++;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <stdio.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 200000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);
const int ABC = 26;

int main() {
  // freopen("a.in", "r", stdin);
  // freopen("a.out", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  // ll TL = 1.95 * CLOCKS_PER_SEC;
  // clock_t time = clock();
  int n, m;
  cin >> n >> m;
  vector<int> g[n];
  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(i, 0, n) {
    bool ok1 = false, ok2 = false;
    for (int j : g[i]) {
      if (j == 0)
        ok1 = true;
      if (j == n - 1)
        ok2 = true;
    }
    if (ok1 && ok2) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <stdio.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 200000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);
const int ABC = 26;

int main() {
  // freopen("a.in", "r", stdin);
  // freopen("a.out", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  // ll TL = 1.95 * CLOCKS_PER_SEC;
  // clock_t time = clock();
  int n, m;
  cin >> n >> m;
  vector<int> g[n];
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(i, 0, n) {
    bool ok1 = false, ok2 = false;
    for (int j : g[i]) {
      if (j == 0)
        ok1 = true;
      if (j == n - 1)
        ok2 = true;
    }
    if (ok1 && ok2) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
struct node {
  vector<int> Ve;
} N[200000 + 10];
int symbol[200000];
int flag = 0;
void dfs(int now, int end, int sum) {

  symbol[now] = 1;
  if (flag == 1)
    return;
  if (sum == 2) {
    if (now == end)
      flag = 1;
    return;
  }
  for (int i = 0; i < N[now].Ve.size(); i++) {
    if (symbol[N[now].Ve[i]] == 0)
      dfs(N[now].Ve[i], end, sum + 1);
  }
  symbol[now] = 1;
}
int main() {
  int N_, M;
  scanf("%d %d", &N_, &M);
  while (M--) {
    int a1, a2;
    scanf("%d%d", &a1, &a2);
    N[a1].Ve.push_back(a2);
    N[a2].Ve.push_back(a1);
  }
  dfs(1, N_, 0);
  if (flag)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");
  printf("\n");
  return 0;
}

Fixed submission:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
struct node {
  vector<int> Ve;
} N[200000 + 10];
int symbol[200000 + 10];
int flag = 0;
void dfs(int now, int end, int sum) {

  symbol[now] = 1;
  if (flag == 1)
    return;
  if (sum == 2) {
    if (now == end)
      flag = 1;
    return;
  }
  for (int i = 0; i < N[now].Ve.size(); i++) {
    if (symbol[N[now].Ve[i]] == 0)
      dfs(N[now].Ve[i], end, sum + 1);
  }
  symbol[now] = 1;
}
int main() {
  int N_, M;
  scanf("%d %d", &N_, &M);
  while (M--) {
    int a1, a2;
    scanf("%d%d", &a1, &a2);
    N[a1].Ve.push_back(a2);
    N[a2].Ve.push_back(a1);
  }
  dfs(1, N_, 0);
  if (flag)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");
  printf("\n");
  return 0;
}
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 INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

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

char dif = 'A' - 'a';

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  bool flag[112345] = {false}, ans = false;
  ll a[112345], b[112345];
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (a[i] == 1)
      flag[b[i]] = true;
    if (b[i] == 1)
      flag[a[i]] = true;
  }
  rep(i, m) {
    if (a[i] == n && flag[b[i]] == true)
      ans = true;
    if (b[i] == n && flag[a[i]] == true)
      ans = true;
  }
  if (ans)
    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 INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

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

char dif = 'A' - 'a';

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  bool flag[212345] = {false}, ans = false;
  ll a[212345], b[212345];
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (a[i] == 1)
      flag[b[i]] = true;
    if (b[i] == 1)
      flag[a[i]] = true;
  }
  rep(i, m) {
    if (a[i] == n && flag[b[i]] == true)
      ans = true;
    if (b[i] == n && flag[a[i]] == true)
      ans = true;
  }
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ld long double
#define vll vector<long long>
#define pll pair<long long, long long>

const ll N = 1e5 + 10;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
vll adj[N];
ll dis[N];
bool vis[N];
queue<ll> q;
int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, m;
  cin >> n >> m;

  for (int i = 1; i <= m; i++) {
    ll u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }

  q.push(1);
  dis[1] = 0;
  while (!q.empty()) {
    ll p = q.front();
    q.pop();
    for (auto v : adj[p]) {
      if (vis[v] == false) {
        vis[v] = true;
        q.push(v);
        dis[v] = dis[p] + 1;
      }
    }
  }
  if (dis[n] == 2)
    cout << "POSSIBLE\n";
  else
    cout << "IMPOSSIBLE\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ld long double
#define vll vector<long long>
#define pll pair<long long, long long>

const ll N = 2e5 + 10;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
vll adj[N];
ll dis[N];
bool vis[N];
queue<ll> q;
int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, m;
  cin >> n >> m;

  for (int i = 1; i <= m; i++) {
    ll u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }

  q.push(1);
  dis[1] = 0;
  while (!q.empty()) {
    ll p = q.front();
    q.pop();
    for (auto v : adj[p]) {
      if (vis[v] == false) {
        vis[v] = true;
        q.push(v);
        dis[v] = dis[p] + 1;
      }
    }
  }
  if (dis[n] == 2)
    cout << "POSSIBLE\n";
  else
    cout << "IMPOSSIBLE\n";
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <thread>
#include <vector>

using namespace std;

// const bool debug = false;

#ifndef M_PI
const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
// #define ll long long
const int mod = int(1e9) + 7;
// const int inf = 1e7;
// const long long infLL = 1e16;
// const int MX2 = 10100500; //  e7
// const long long INF = 1e18 + 0.5;
const int MX = 100500; //       e6
const int SZ = 122;

int a[MX];

int main() {
  ios_base::sync_with_stdio(false);
  // freopen("/Users/ozzy/Documents/in.txt","r", stdin);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u > v)
      swap(u, v);
    if (u == 0)
      a[v] |= 1;
    if (v == n - 1)
      a[u] |= 2;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 3) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <thread>
#include <vector>

using namespace std;

// const bool debug = false;

#ifndef M_PI
const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
// #define ll long long
const int mod = int(1e9) + 7;
// const int inf = 1e7;
// const long long infLL = 1e16;
// const int MX2 = 10100500; //  e7
// const long long INF = 1e18 + 0.5;
const int MX = 300500; //       e6
const int SZ = 122;

int a[MX];

int main() {
  ios_base::sync_with_stdio(false);
  // freopen("/Users/ozzy/Documents/in.txt","r", stdin);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u > v)
      swap(u, v);
    if (u == 0)
      a[v] |= 1;
    if (v == n - 1)
      a[u] |= 2;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 3) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int main() {
  int n, m;
  int a[SIZE], b[SIZE];
  int in1[SIZE] = {}, inn[SIZE] = {};
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    scanf("%d%d", a + i, b + i);

    if (a[i] > b[i])
      swap(a[i], b[i]);

    if (a[i] == 1)
      in1[b[i] - 1] = true;

    if (b[i] == n)
      inn[a[i] - 1] = true;
  }

  bool ans = false;

  for (int i = 1; i < n - 1; i++) {
    ans |= in1[i] && inn[i];
  }

  puts(ans ? "POSSIBLE" : "IMPOSSIBLE");

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

int main() {
  int n, m;
  int a[SIZE], b[SIZE];
  int in1[SIZE] = {}, inn[SIZE] = {};
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    scanf("%d%d", a + i, b + i);

    if (a[i] > b[i])
      swap(a[i], b[i]);

    if (a[i] == 1)
      in1[b[i] - 1] = true;

    if (b[i] == n)
      inn[a[i] - 1] = true;
  }

  bool ans = false;

  for (int i = 1; i < n - 1; i++) {
    ans |= in1[i] && inn[i];
  }

  puts(ans ? "POSSIBLE" : "IMPOSSIBLE");

  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

void solve(long long N, long long M, vector<long long> a, vector<long long> b) {
  int memo1[200001] = {0};
  int memo2[200001] = {0};
  for (long long i = 0; i < N; i++) {
    if (a[i] == 1) {
      memo1[b[i] - 1] = 1;
    }
    if (b[i] == N) {
      memo2[a[i] - 1] = 1;
    }
  }
  string ans = "IMPOSSIBLE";
  for (long long i = 0; i < N; i++) {
    if (memo1[i] == 1 && memo2[i] == 1) {
      ans = "POSSIBLE";
      break;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  long long M;
  scanf("%lld", &N);
  scanf("%lld", &M);
  vector<long long> b(M - 1 + 1);
  vector<long long> a(M - 1 + 1);
  for (int i = 0; i <= M - 1; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
  }
  solve(N, M, a, b);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

void solve(long long N, long long M, vector<long long> a, vector<long long> b) {
  int memo1[200001] = {0};
  int memo2[200001] = {0};
  for (long long i = 0; i < M; i++) {
    if (a[i] == 1) {
      memo1[b[i] - 1] = 1;
    }
    if (b[i] == N) {
      memo2[a[i] - 1] = 1;
    }
  }
  string ans = "IMPOSSIBLE";
  for (long long i = 0; i < N; i++) {
    if (memo1[i] == 1 && memo2[i] == 1) {
      ans = "POSSIBLE";
      break;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  long long M;
  scanf("%lld", &N);
  scanf("%lld", &M);
  vector<long long> b(M - 1 + 1);
  vector<long long> a(M - 1 + 1);
  for (int i = 0; i <= M - 1; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
  }
  solve(N, M, a, b);
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9 + 7;
const int N = 100000 + 5;
const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
using namespace std;
struct Edge {
  int to;
  int next;
} edge[N];
int n, m;
int tot, head[N];
void addEdge(int from, int to) {
  edge[++tot].to = to;
  edge[tot].next = head[from];
  head[from] = tot;
}
bool dfs(int s, int step) {
  if (s == n && step == 2)
    return true;
  for (int i = head[s]; i != -1; i = edge[i].next) {
    int to = edge[i].to;
    if (dfs(to, step + 1))
      return true;
  }
  return false;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addEdge(x, y);
  }

  bool flag = dfs(1, 0);
  if (flag)
    printf("POSSIBLE\n");
  else
    printf("IMPOSSIBLE\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9 + 7;
const int N = 200000 + 5;
const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
using namespace std;
struct Edge {
  int to;
  int next;
} edge[N];
int n, m;
int tot, head[N];
void addEdge(int from, int to) {
  edge[++tot].to = to;
  edge[tot].next = head[from];
  head[from] = tot;
}
bool dfs(int s, int step) {
  if (s == n && step == 2)
    return true;
  for (int i = head[s]; i != -1; i = edge[i].next) {
    int to = edge[i].to;
    if (dfs(to, step + 1))
      return true;
  }
  return false;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addEdge(x, y);
  }

  bool flag = dfs(1, 0);
  if (flag)
    printf("POSSIBLE\n");
  else
    printf("IMPOSSIBLE\n");
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18) + 7;
const llong mod = 1e9 + 7;

struct data {
  int place;
  int cost;

  data(){};
  data(int place, int cost) : place(place), cost(cost) {}

  bool operator<(const data &ri) const { return cost < ri.cost; }
  bool operator>(const data &ri) const { return cost > ri.cost; }
};

int N, M;
vector<vector<P>> edges;

llong Dijkstra(int start, int goal) {
  priority_queue<data> q;
  vector<llong> dis(edges.size(), inf);
  dis[start] = 0;

  q.push(data(start, 0));
  while (q.size()) {
    data now = q.top();
    q.pop();
    if (now.place == goal)
      return now.cost;
    if (dis[now.place] < now.cost)
      continue;

    for (int i = 0; i < edges[now.place].size(); i++) {
      P edge = edges[now.place][i];
      data next(edge.first, now.cost + edge.second);
      if (dis[next.place] <= next.cost)
        continue;
      dis[next.place] = next.cost;
      q.push(next);
    }
  }

  return -1;
}

int main() {
  cin >> N >> M;
  edges.resize(N + 1, vector<P>());

  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    edges[a].push_back(P(b, 1));
    edges[b].push_back(P(a, 1));
  }

  if (Dijkstra(1, N) == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18) + 7;
const llong mod = 1e9 + 7;

struct data {
  int place;
  int cost;

  data(){};
  data(int place, int cost) : place(place), cost(cost) {}

  bool operator<(const data &ri) const { return cost < ri.cost; }
  bool operator>(const data &ri) const { return cost > ri.cost; }
};

int N, M;
vector<vector<P>> edges;

llong Dijkstra(int start, int goal) {
  priority_queue<data> q;
  vector<llong> dis(edges.size(), inf);
  dis[start] = 0;

  q.push(data(start, 0));
  while (q.size()) {
    data now = q.top();
    q.pop();
    if (now.place == goal)
      return now.cost;
    if (now.cost >= 2)
      continue;
    if (dis[now.place] < now.cost)
      continue;

    for (int i = 0; i < edges[now.place].size(); i++) {
      P edge = edges[now.place][i];
      data next(edge.first, now.cost + edge.second);
      if (dis[next.place] <= next.cost)
        continue;
      dis[next.place] = next.cost;
      q.push(next);
    }
  }

  return -1;
}

int main() {
  cin >> N >> M;
  edges.resize(N + 1, vector<P>());

  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    edges[a].push_back(P(b, 1));
    edges[b].push_back(P(a, 1));
  }

  if (Dijkstra(1, N) == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
//( ͡° ͜ʖ ͡°) °º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤º°` looking at my code...

#define ONLINE_JUDGE // in case i forget to uncomment this, sometimes the grader
                     // defines the macro ^.^
#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>
#else
#include "stdc++.h"
#endif
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define INF (int)1e9

#define int long long
using namespace std;

signed main() {
#ifndef ONLINE_JUDGE
  freopen("/Users/kdkdk/Desktop/input.txt", "r", stdin);
  // freopen("/Users/kdkdk/Desktop/output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> bridges(n);
  for (int i = 0; i < m; ++i)
    cin >> bridges[i].first >> bridges[i].second;
  unordered_map<int, bool> possible;
  for (int i = 0; i < m; ++i)
    if (bridges[i].second == n)
      possible[bridges[i].first] = true;
  bool totPossible = false;
  for (int i = 0; i < m && !totPossible; ++i)
    if (bridges[i].first == 1)
      if (possible.count(bridges[i].second) > 0 && possible[bridges[i].second])
        totPossible = true;
  cout << (totPossible ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}

Fixed submission:
//( ͡° ͜ʖ ͡°) °º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤º°` looking at my code...

#define ONLINE_JUDGE // in case i forget to uncomment this, sometimes the grader
                     // defines the macro ^.^
#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>
#else
#include "stdc++.h"
#endif
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define INF (int)1e9

#define int long long
using namespace std;

signed main() {
#ifndef ONLINE_JUDGE
  freopen("/Users/kdkdk/Desktop/input.txt", "r", stdin);
  // freopen("/Users/kdkdk/Desktop/output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> bridges(m);
  for (int i = 0; i < m; ++i)
    cin >> bridges[i].first >> bridges[i].second;
  unordered_map<int, bool> possible;
  for (int i = 0; i < m; ++i)
    if (bridges[i].second == n)
      possible[bridges[i].first] = true;
  bool totPossible = false;
  for (int i = 0; i < m && !totPossible; ++i)
    if (bridges[i].first == 1)
      if (possible.count(bridges[i].second) > 0 && possible[bridges[i].second])
        totPossible = true;
  cout << (totPossible ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 200010;
int n, m;

vector<int> e[N];

inline int read() {
  char ch = getchar();
  int x = 0;
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}

int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int x, y;
    x = read();
    y = read();
    bool flag = true;
    for (int j = 0; j < e[x].size(); j++)
      if (e[x][j] == y) {
        flag = false;
        break;
      }
    if (flag) {
      e[x].push_back(y);
      e[y].push_back(x);
    }
  }
  for (int i = 2; i < n; i++) {
    bool flag1 = false, flag2 = false;
    for (int j = 0; j < e[i].size(); j++) {
      if (e[i][j] == 1)
        flag1 = true;
      if (e[i][j] == n)
        flag2 = true;
      if (flag1 && flag2) {
        puts("POSSIBLE");
        return 0;
      }
    }
  }
  puts("IMPOSSIBLE");
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 200010;
int n, m;

vector<int> e[N];

inline int read() {
  char ch = getchar();
  int x = 0;
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}

int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int x, y;
    x = read();
    y = read();
    /*bool flag = true;
    for (int j = 0; j < e[x].size(); j ++)
            if (e[x][j] == y){
                    flag = false;
                    break;
            }
    if (flag){*/
    e[x].push_back(y);
    e[y].push_back(x);
    //}
  }
  for (int i = 2; i < n; i++) {
    bool flag1 = false, flag2 = false;
    for (int j = 0; j < e[i].size(); j++) {
      if (e[i][j] == 1)
        flag1 = true;
      if (e[i][j] == n)
        flag2 = true;
      if (flag1 && flag2) {
        puts("POSSIBLE");
        return 0;
      }
    }
  }
  puts("IMPOSSIBLE");
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define inf 0x3f3f3f3f
#define esp 1e-7
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

int n, m;

vector<int> from[200050];
int visited[200050];
int boolean;

int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int x;
    int y;
    x = read();
    y = read();
    from[x].push_back(y);
    from[y].push_back(x);
  }
  boolean = 0;
  for (int i = 1; i <= n; i++) {
    int counts = 0;
    for (int j = 0, maxn = from[i].size(); j <= maxn; j++) {
      if (from[i][j] == 1)
        counts++;
      if (from[i][j] == n)
        counts++;
    }
    if (counts == 2) {
      boolean = 1;
      break;
    }
  }
  if (boolean)
    printf("POSSIBLE\n");
  else
    printf("IMPOSSIBLE\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define inf 0x3f3f3f3f
#define esp 1e-7
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

int n, m;

vector<int> from[200050];
int visited[200050];
int boolean;

int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int x;
    int y;
    x = read();
    y = read();
    from[x].push_back(y);
    from[y].push_back(x);
  }
  boolean = 0;
  for (int i = 1; i <= n; i++) {
    int counts = 0;
    for (int j = 0, maxn = from[i].size(); j < maxn; j++) {
      if (from[i][j] == 1)
        counts++;
      if (from[i][j] == n)
        counts++;
    }
    if (counts == 2) {
      boolean = 1;
      break;
    }
  }
  if (boolean)
    printf("POSSIBLE\n");
  else
    printf("IMPOSSIBLE\n");
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

set<int> g[100005];
int main() {
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].insert(y);
    g[y].insert(x);
  }
  set<int>::iterator it;
  bool f = 0;
  for (it = g[1].begin(); it != g[1].end(); it++) {
    int v = *it;
    if (g[v].find(n) != g[v].end()) {
      cout << "POSSIBLE" << endl;
      f = 1;
      break;
    }
  }

  if (f == 0)
    cout << "IMPOSSIBLE" << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

set<int> g[200005];
int main() {
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].insert(y);
    g[y].insert(x);
  }
  set<int>::iterator it;
  bool f = 0;
  for (it = g[1].begin(); it != g[1].end(); it++) {
    int v = *it;
    if (g[v].find(n) != g[v].end()) {
      cout << "POSSIBLE" << endl;
      f = 1;
      break;
    }
  }

  if (f == 0)
    cout << "IMPOSSIBLE" << endl;
}