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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int ans = 0;
void aout(void) { cout << ans << endl; }
void out(int a) { cout << a << endl; }
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, i, j;
  cin >> n >> m;
  pair<int, int> p[m];
  for (i = 0; i < m; ++i)
    cin >> p[i].first >> p[i].second;
  vector<int> d, s;
  for (i = 0; i < m; ++i) {
    if (p[i].second == n)
      d.push_back(p[i].first);
    if (p[i].first == 1)
      s.push_back(p[i].second);
  }
  for (i = 0; i < d.size(); ++i) {
    for (j = 0; j < s.size(); ++j) {
      if (d[i] == s[j]) {
        cout << "POSSIBLE\n";
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int ans = 0;
void aout(void) { cout << ans << endl; }
void out(int a) { cout << a << endl; }
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, i, j;
  cin >> n >> m;
  pair<int, int> p[m];
  for (i = 0; i < m; ++i)
    cin >> p[i].first >> p[i].second;
  vector<int> d, s;
  for (i = 0; i < m; ++i) {
    if (p[i].second == n)
      d.push_back(p[i].first);
    if (p[i].first == 1)
      s.push_back(p[i].second);
  }
  sort(d.begin(), d.end());
  sort(s.begin(), s.end());
  i = 0;
  j = 0;
  while (i < d.size() && j < s.size()) {
    if (d[i] > s[j])
      ++j;
    else if (d[i] < s[j])
      ++i;
    else {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i <= int(n); ++i)
#define all(a) a.begin(), a.end()
#define lb(s, x) lower_bound(all(s), x) - s.begin()
#define debug(x) cout << #x << ": " << x << endl
#define INF 1e9
typedef long long ll;

vector<int> g[200010];
int d[200010];

void dfs(int v, int depth) {
  if (depth > 2)
    return;
  d[v] = depth;
  for (int u : g[v]) {
    dfs(u, depth + 1);
  }
}

int main(void) {
  int n, m;
  cin >> n >> m;

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, 0);
  cout << (d[n - 1] == 2 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i <= int(n); ++i)
#define all(a) a.begin(), a.end()
#define lb(s, x) lower_bound(all(s), x) - s.begin()
#define debug(x) cout << #x << ": " << x << endl
#define INF 1e9
typedef long long ll;

vector<int> g[200010];
int d[200010];

void dfs(int v, int depth) {
  if (depth > 2 || d[v] > 0)
    return;
  d[v] = depth;
  for (int u : g[v]) {
    dfs(u, depth + 1);
  }
}

int main(void) {
  int n, m;
  cin >> n >> m;

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, 0);
  cout << (d[n - 1] == 2 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
#define MOD (long long)(1e9 + 7)
#define MAX_VAL (int)(1e5)

int u[200000], N;
vector<int> G[200000];

int foo() {
  for (int y : G[1]) {
    for (int z : G[y]) {
      if (z == N)
        return true;
    }
  }
  return false;
}

int main() {
  int M, flag = false, a, b;

  cin >> N >> M;

  for (int i = 1; i <= M; i++) {
    cin >> a >> b;
    if (a == 1 || b == 1 || a == N || b == N) {
      G[a].push_back(b);
      G[b].push_back(a);
    }
  }
  cout << (foo() ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
#define MOD (long long)(1e9 + 7)
#define MAX_VAL (int)(1e5)

int u[200000], N;
vector<int> G[201010];

int foo() {
  for (int y : G[1]) {
    for (int z : G[y]) {
      if (z == N)
        return true;
    }
  }
  return false;
}

int main() {
  int M, flag = false, a, b;

  cin >> N >> M;

  for (int i = 1; i <= M; i++) {
    cin >> a >> b;
    if (a == 1 || b == 1 || a == N || b == N) {
      G[a].push_back(b);
      G[b].push_back(a);
    }
  }
  cout << (foo() ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 0;
  cin >> n >> m;
  vector<int> v[m + 3];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
  }
  for (int i = 0; i < v[1].size(); i++) {
    int x = v[1][i];
    if (find(v[x].begin(), v[x].end(), n) != v[x].end()) {
      f = 1;
      break;
    }
  }
  if (f)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 0;
  cin >> n >> m;
  vector<int> v[n + 3];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
  }
  for (int i = 0; i < v[1].size(); i++) {
    int x = v[1][i];
    if (find(v[x].begin(), v[x].end(), n) != v[x].end()) {
      f = 1;
      break;
    }
  }
  if (f)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
#include <utility>
using namespace std;

int n, m;
set<pair<int, int>> v;
set<int> w;

void center_point() {
  for (auto x : v) {
    if (n == x.first)
      w.insert(x.second);
    else if (n == x.second)
      w.insert(x.first);
  }
}

bool search() {
  for (auto x : w) {
    for (auto y : v) {
      auto a = y.first;
      auto b = y.second;
      if (a == x && b == 1)
        return true;
      if (b == x && a == 1)
        return true;
    }
  }
  return false;
}

void solve() {
  center_point(); // Nから逆にたどって行ける島のリストをwに突っ込む
  if (search()) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.insert(make_pair(a, b));
  }
  solve();
}

Fixed submission:
#include <iostream>
#include <set>
#include <utility>
using namespace std;

int n, m;
set<pair<int, int>> v;
set<int> w;

void center_point() {
  for (auto x : v) {
    if (n == x.first)
      w.insert(x.second);
    else if (n == x.second)
      w.insert(x.first);
  }
}

bool search() {
  for (auto x : w) {
    if (v.find(make_pair(x, 1)) != v.end())
      return true;
    if (v.find(make_pair(1, x)) != v.end())
      return true;
  }
  return false;
}

void solve() {
  center_point(); // Nから逆にたどって行ける島のリストをwに突っ込む
  if (search()) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.insert(make_pair(a, b));
  }
  solve();
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

size_t N;
int M;
vector<int> pass1, passN;

int main() {
  cin >> N >> M;

  int a, b;

  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (a == 1) {
      pass1.push_back(b);
    } else if (b == N) {
      passN.push_back(a);
    }
  }

  for (int an : pass1) {
    for (int bn : passN) {
      if (an == bn) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

size_t N;
int M;
vector<int> pass1, passN;

int main() {
  cin >> N >> M;

  int a, b;

  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (a == 1) {
      pass1.push_back(b);
    } else if (b == N) {
      passN.push_back(a);
    }
  }

  sort(pass1.begin(), pass1.end());
  sort(passN.begin(), passN.end());

  size_t p1, pN;
  p1 = pN = 0;

  while (p1 < pass1.size() && pN < passN.size()) {
    if (pass1[p1] == passN[pN]) {
      cout << "POSSIBLE" << endl;
      return 0;
    } else if (pass1[p1] < passN[pN]) {
      p1++;
    } else {
      pN++;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.emplace_back(a, b);
  }
  bool ans = false;
  bool point[200] = {false};
  for (int i = 0; i < 200; i++) {
    point[i] = false;
  }
  for (int i = 0; i < m; i++) {
    if (v[i].first == 1)
      point[v[i].second] = true;
  }
  for (int i = 0; i < m; i++) {
    if (v[i].second == n) {
      if (point[v[i].first])
        ans = true;
    }
  }
  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.emplace_back(a, b);
  }
  bool ans = false;
  bool point[200001] = {false};
  for (int i = 0; i < 200001; i++) {
    point[i] = false;
  }
  for (int i = 0; i < m; i++) {
    if (v[i].first == 1)
      point[v[i].second] = true;
  }
  for (int i = 0; i < m; i++) {
    if (v[i].second == n) {
      if (point[v[i].first])
        ans = true;
    }
  }
  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}
Problem p03645 (C++)

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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;
typedef long long int ll;

const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> Glaph(N + 10);
  for (int j = 0; j < M; ++j) {
    int a, b;
    cin >> a >> b;
    Glaph[a].push_back(b);
    Glaph[b].push_back(a);
  }

  for (int from : Glaph[1]) {
    for (int to : Glaph[from]) {
      if (Glaph[from][to] == N) {
        printf("%s\n", "POSSIBLE");
        return 0;
      }
    }
  }
  printf("%s\n", "IMPOSSIBLE");
  return 0;
}


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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;
typedef long long int ll;

const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> Glaph(N + 10);
  for (int j = 0; j < M; ++j) {
    int a, b;
    cin >> a >> b;
    Glaph[a].push_back(b);
    Glaph[b].push_back(a);
  }
  for (int i = 0; i < (int)Glaph[1].size(); ++i) {
    int from = Glaph[1][i];
    for (int j = 0; j < (int)Glaph[from].size(); ++j) {
      int to = Glaph[from][j];
      if (to == N) {
        printf("%s\n", "POSSIBLE");
        return 0;
      }
    }
  }
  printf("%s\n", "IMPOSSIBLE");
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9 + 7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

ll gcd(ll m, ll n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / gcd(a, b) * b;
}
int main() {

  ll N, M;
  cin >> N >> M;

  vector<ll> a(M);
  vector<ll> b(M);
  vector<pair<ll, ll>> c(M);
  vector<ll> F;
  vector<ll> E;

  rep(i, M) {
    cin >> a[i] >> b[i];
    c[i].first = a[i];
    c[i].second = b[i];
  }
  sort(all(c));

  for (ll i = 0; i < M; i++) {
    if (c[i].first == 1) {
      F.push_back(c[i].second);
    }
  }

  for (ll i = 0; i < M; i++) {
    if (c[i].second == N) {
      E.push_back(c[i].first);
    }
  }
  if (F.size() == 0 || E.size() == 0) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    bool flag = false;

    for (ll i = 0; i < F.size(); i++) {
      for (ll j = 0; j < E.size(); j++) {
        if (F[i] == E[j]) {
          flag = true;
          break;
        }
      }
      if (flag) {
        break;
      }
    }

    if (flag) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9 + 7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

ll gcd(ll m, ll n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / gcd(a, b) * b;
}
int main() {

  ll N, M;
  cin >> N >> M;

  vector<ll> a(M);
  vector<ll> b(M);
  vector<pair<ll, ll>> c(M);
  vector<ll> F;
  vector<ll> E;

  rep(i, M) {
    cin >> a[i] >> b[i];
    c[i].first = a[i];
    c[i].second = b[i];
  }
  sort(all(c));

  for (ll i = 0; i < M; i++) {
    if (c[i].first == 1) {
      F.push_back(c[i].second);
    }
  }

  for (ll i = 0; i < M; i++) {
    if (c[i].second == N) {
      E.push_back(c[i].first);
    }
  }
  if (F.size() == 0 || E.size() == 0) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    bool flag = false;

    for (ll i = 0; i < F.size(); i++) {
      if (E[lower_bound(all(E), F[i]) - E.begin()] == F[i]) {
        flag = true;
        break;
      }
    }

    if (flag) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  }
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <queue>
#include <vector>

int dist[200010];

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  for (int i = 0; i < n; i++)
    dist[i] = -1;

  queue<int> que;
  dist[0] = 0;
  que.push(0);

  while (!que.empty()) {
    int s = que.front();

    for (int i = 0; i < G[s].size(); i++) {
      int g = G[s][i];

      if (dist[g] >= 0 && dist[g] > dist[s] + 1)
        continue;

      dist[g] = dist[s] + 1;

      que.push(g);
    }

    que.pop();
  }

  if (dist[n - 1] == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <queue>
#include <vector>

int dist[200010];

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  for (int i = 0; i < n; i++)
    dist[i] = -1;

  queue<int> que;
  dist[0] = 0;
  que.push(0);

  while (!que.empty()) {
    int s = que.front();

    for (int i = 0; i < G[s].size(); i++) {
      int g = G[s][i];

      if (dist[g] >= 0 && dist[g] < dist[s] + 1)
        continue;

      dist[g] = dist[s] + 1;

      que.push(g);
    }

    que.pop();
  }

  if (dist[n - 1] == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  set<int> from;
  set<int> to;
  int f, t;

  for (int i = 0; i < M; i++) {
    cin >> f >> t;

    if (f == 1) {
      from.insert(t);
    }
    if (t == N) {
      to.insert(f);
    }
  }

  for (auto i = from.begin(); i != from.end(); ++i) {
    for (auto j = to.begin(); j != to.end(); ++j) {
      if (*i == *j) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  set<int> from;
  set<int> to;
  int f, t;

  for (int i = 0; i < M; i++) {
    cin >> f >> t;

    if (f == 1) {
      from.insert(t);
    }
    if (t == N) {
      to.insert(f);
    }
  }

  for (auto i = from.begin(); i != from.end(); ++i) {
    if (to.find(*i) != to.end()) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> sn, en;
  for (int i = 0; i < M; ++i) {
    int c, d;
    cin >> c >> d;
    if (c == 1)
      sn.push_back(d);
    else if (d == N)
      en.push_back(c);
  }

  sort(sn.begin(), sn.end());
  sort(en.begin(), en.end());

  int s_size = sn.size(), e_size = en.size();
  for (int i = 0, j = 0; i < s_size; ++i, --j) {
    for (; j < e_size; ++j) {
      if (sn[i] < en[j])
        break;
      if (sn[i] == en[j]) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> sn, en;
  for (int i = 0; i < M; ++i) {
    int c, d;
    cin >> c >> d;
    if (c == 1)
      sn.push_back(d);
    else if (d == N)
      en.push_back(c);
  }

  sort(sn.begin(), sn.end());
  sort(en.begin(), en.end());

  int s_size = sn.size(), e_size = en.size();
  for (int i = 0, j = 0; i < s_size; ++i, j = j == 0 ? 0 : j - 1) {
    for (; j < e_size; ++j) {
      if (sn[i] < en[j])
        break;
      if (sn[i] == en[j]) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <queue>
using namespace std;
struct edge {
  int to, next;
} e[210000];
int first[210000];
queue<int> q;
void addedge(int num, int x, int y) {
  e[num].to = y;
  e[num].next = first[x];
  first[x] = num;
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    addedge(2 * i - 1, x, y);
    addedge(2 * i, y, x);
  }
  for (int i = first[1]; i; i = e[i].next)
    if (e[i].to == n) {
      printf("POSSIBLE\n");
      return 0;
    } else
      q.push(e[i].to);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = first[now]; i; i = e[i].next)
      if (e[i].to == n) {
        printf("POSSIBLE\n");
        return 0;
      }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}

Fixed submission:
#include <cstdio>
#include <queue>
using namespace std;
struct edge {
  int to, next;
} e[410000];
int first[210000];
queue<int> q;
void addedge(int num, int x, int y) {
  e[num].to = y;
  e[num].next = first[x];
  first[x] = num;
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    addedge(2 * i - 1, x, y);
    addedge(2 * i, y, x);
  }
  for (int i = first[1]; i; i = e[i].next)
    if (e[i].to == n) {
      printf("POSSIBLE\n");
      return 0;
    } else
      q.push(e[i].to);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = first[now]; i; i = e[i].next)
      if (e[i].to == n) {
        printf("POSSIBLE\n");
        return 0;
      }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}
Problem p03645 (C++)

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

using namespace std;
typedef long long ll;

vector<vector<int>> vec(200000, vector<int>());
int cnt[200000];

void s(int c, int to) {
  if (c > 2) {
    return;
  }
  cnt[to] = c;
  for (int i = 0; i < vec[to].size(); i++) {
    s(c + 1, vec[to][i]);
  }
}

int main() {
  int N, M;
  cin >> N >> M;

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

  s(0, 1);

  if (cnt[N] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

vector<vector<int>> vec(200010, vector<int>());
int cnt[200010];

void s(int c, int to) {
  if (c > 2) {
    return;
  }
  cnt[to] = c;
  for (int i = 0; i < vec[to].size(); i++) {
    s(c + 1, vec[to][i]);
  }
}

int main() {
  int N, M;
  cin >> N >> M;

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

  s(0, 1);

  if (cnt[N] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, j) for (int i = (j); i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)
#define ssort(n) sort((n).begin(), (n).end())
using ll = long long;
using ld = long double;
typedef pair<int, int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010
#define OK cout << "POSSIBLE" << endl
#define NG cout << "IMPOSSIBLE" << endl

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);

  rep(i, M) { cin >> a[i] >> b[i]; }
  vector<queue<int>> ship(M + 1);
  rep(i, M) { ship[a[i]].push(b[i]); }
  bool result = false;
  while (!ship[1].empty()) {
    int val = ship[1].front();
    while (!ship[val].empty()) {
      if (ship[val].front() == N) {
        result = true;
        break;
      }
      ship[val].pop();
    }
    ship[1].pop();
    if (result)
      break;
  }

  if (result) {
    OK;
  } else {
    NG;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, j) for (int i = (j); i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)
#define ssort(n) sort((n).begin(), (n).end())
using ll = long long;
using ld = long double;
typedef pair<int, int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010
#define OK cout << "POSSIBLE" << endl
#define NG cout << "IMPOSSIBLE" << endl

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);

  rep(i, M) { cin >> a[i] >> b[i]; }
  vector<queue<int>> ship(N + 1);
  rep(i, M) { ship[a[i]].push(b[i]); }
  bool result = false;
  while (!ship[1].empty()) {
    int val = ship[1].front();
    while (!ship[val].empty()) {
      if (ship[val].front() == N) {
        result = true;
        break;
      }
      ship[val].pop();
    }
    ship[1].pop();
    if (result)
      break;
  }

  if (result) {
    OK;
  } else {
    NG;
  }
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
vector<int> G[20001];
void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    add_edge(temp1, temp2);
  }
  for (int node : G[1]) {
    for (int noden : G[node]) {
      if (noden == n) {
        cout << "POSSIBLE"
             << "\n";
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE"
       << "\n";
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
vector<int> G[200001];
void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    add_edge(temp1, temp2);
  }
  for (int node : G[1]) {
    for (int noden : G[node]) {
      if (noden == n) {
        cout << "POSSIBLE"
             << "\n";
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE"
       << "\n";
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int nxt[200001], head[200001], to[200001], cnt;
void add(int u, int v) {
  cnt++;
  nxt[cnt] = head[u];
  head[u] = cnt;
  to[cnt] = v;
}
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  for (int i = head[1]; i != 0; i = nxt[i]) {
    if (to[i] == n) {
      cout << "POSSIBLE";
      return 0;
    } else {
      for (int j = head[to[i]]; j != 0; j = nxt[j]) {
        if (to[j] == n) {
          cout << "POSSIBLE";
          return 0;
        }
      }
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int nxt[400001], head[400001], to[400001], cnt;
void add(int u, int v) {
  cnt++;
  nxt[cnt] = head[u];
  head[u] = cnt;
  to[cnt] = v;
}
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  for (int i = head[1]; i != 0; i = nxt[i]) {
    if (to[i] == n) {
      cout << "POSSIBLE";
      return 0;
    } else {
      for (int j = head[to[i]]; j != 0; j = nxt[j]) {
        if (to[j] == n) {
          cout << "POSSIBLE";
          return 0;
        }
      }
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> ip;
typedef pair<ll, ll> lp;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<ip> ship(M);
  set<int> from1;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      from1.insert(b);
    ship[i].first = a;
    ship[i].second = b;
  }
  bool ok = false;
  rep(i, N) {
    if (ship[i].second == N) {
      if (from1.count(ship[i].first) == 1) {
        ok = true;
      }
    }
  }
  cout << ((ok) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> ip;
typedef pair<ll, ll> lp;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<ip> ship(M);
  set<int> from1;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      from1.insert(b);
    ship[i].first = a;
    ship[i].second = b;
  }
  bool ok = false;
  rep(i, M) {
    if (ship[i].second == N) {
      if (from1.count(ship[i].first) == 1) {
        ok = true;
      }
    }
  }
  cout << ((ok) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}
Problem p03645 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  bool ans = false;
  vector<int> a(m), b(m), c(m, 0);
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++) {
    if (a[i] == 1)
      c[b[i] - 1]++;
    if (b[i] == n)
      c[a[i] - 1]++;
  }
  for (int i = 0; i < c.size(); i++) {
    if (c[i] == 2)
      ans = true;
  }
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  bool ans = false;
  vector<int> a(m), b(m), c(n, 0);
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++) {
    if (a[i] == 1)
      c[b[i] - 1]++;
    if (b[i] == n)
      c[a[i] - 1]++;
  }
  for (int i = 0; i < c.size(); i++) {
    if (c[i] == 2)
      ans = true;
  }
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 100111, inf = 1000111222;

bool from1[max_n];
bool ton[max_n];

int main() {
  // freopen("input.txt", "r", stdin);
  int n, m, from, to;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> from >> to;
    if (from == 1) {
      from1[to] = true;
    }
    if (to == n) {
      ton[from] = true;
    }
  }
  for (int i = 2; i < n; ++i) {
    if (from1[i] && ton[i]) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, inf = 1000111222;

bool from1[max_n];
bool ton[max_n];

int main() {
  // freopen("input.txt", "r", stdin);
  int n, m, from, to;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> from >> to;
    if (from == 1) {
      from1[to] = true;
    }
    if (to == n) {
      ton[from] = true;
    }
  }
  for (int i = 2; i < n; ++i) {
    if (from1[i] && ton[i]) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}
Problem p03645 (C++)

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

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return x / g * y;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> ab(N);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }

  bool ok = false;
  int size1 = ab[0].size();
  rep(i, size1) {
    int second = ab[0][i];
    int size2 = ab[second].size();
    rep(j, size2) {
      int third = ab[second][j];
      if (third == N - 1) {
        ok = true;
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }

  if (!ok)
    cout << "IMPOSSIBLE" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, n) for (long long i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return x / g * y;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> ab(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }

  bool ok = false;
  int size1 = ab[0].size();
  rep(i, size1) {
    int second = ab[0][i];
    int size2 = ab[second].size();
    rep(j, size2) {
      int third = ab[second][j];
      if (third == N - 1) {
        ok = true;
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }

  if (!ok)
    cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;

struct edge {
  int to, cost;
};
typedef pair<int, int> P; // firstは最短距離、secondは頂点の番号

int V; // 頂点数
vector<edge> G[100010];
int d[100010]; // 頂点sからの最短距離

void dijkstra(int s) {
  // greater<P>を指定することでfirstが小さい順に取り出せる
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, 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 < 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));
      }
    }
  }
}

signed main() {
  cin >> V;
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    int ONE = 1;
    G[A - 1].push_back(edge{B - 1, ONE});
  }
  dijkstra(0);
  if (d[V - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;

struct edge {
  int to, cost;
};
typedef pair<int, int> P; // firstは最短距離、secondは頂点の番号

int V; // 頂点数
vector<edge> G[200010];
int d[200010]; // 頂点sからの最短距離

void dijkstra(int s) {
  // greater<P>を指定することでfirstが小さい順に取り出せる
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, 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 < 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));
      }
    }
  }
}

signed main() {
  cin >> V;
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    int ONE = 1;
    G[A - 1].push_back(edge{B - 1, ONE});
  }
  dijkstra(0);
  if (d[V - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ", i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

#define MAX_V 100010
struct edge {
  int to;
  int cost;
};
int V;
vector<edge> G[MAX_V];
ll d[MAX_V];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, 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 < 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() {
  int m;
  cin >> V >> m;
  rep(i, 0, m) {
    int p1, p2;
    cin >> p1 >> p2;
    G[p1 - 1].push_back({p2 - 1, 1});
  }
  dijkstra(0);
  if (d[V - 1] > 2)
    printf("IMPOSSIBLE");
  else
    printf("POSSIBLE");
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ", i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

#define MAX_V 200010
struct edge {
  int to;
  int cost;
};
int V;
vector<edge> G[MAX_V];
ll d[MAX_V];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, 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 < 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() {
  int m;
  cin >> V >> m;
  rep(i, 0, m) {
    int p1, p2;
    cin >> p1 >> p2;
    G[p1 - 1].push_back({p2 - 1, 1});
  }
  dijkstra(0);
  if (d[V - 1] > 2)
    printf("IMPOSSIBLE");
  else
    printf("POSSIBLE");
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
int main() {
  ll n, m;
  cin >> n >> m;
  vl a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<ll> start;
  vector<ll> finish;
  rep(i, n) {
    if (a[i] == 1) {
      start.push_back(b[i]);
    }
    if (b[i] == n)
      finish.push_back(a[i]);
  }
  bool ans = false;
  sort(finish.begin(), finish.end());
  rep(i, start.size()) {
    if (std::binary_search(finish.begin(), finish.end(), start[i]))
      ans = true;
  }
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
int main() {
  ll n, m;
  cin >> n >> m;
  vl a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<ll> start;
  vector<ll> finish;
  rep(i, m) {
    if (a[i] == 1) {
      start.push_back(b[i]);
    }
    if (b[i] == n)
      finish.push_back(a[i]);
  }
  bool ans = false;
  sort(finish.begin(), finish.end());
  rep(i, start.size()) {
    if (std::binary_search(finish.begin(), finish.end(), start[i]))
      ans = true;
  }
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  long long r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  int N, M, a, b;
  cin >> N >> M;
  vector<vector<int>> way(N);
  for (size_t i = 0; i < M; i++) {
    cin >> a >> b;
    a--;
    b--;
    way.at(a).push_back(b);
    way.at(b).push_back(a);
  }
  for (size_t i = 0; i < N; i++) {
    sort(way.at(i).begin(), way.at(i).end());
    if (way.at(i).size() != 0 && way.at(i).at(0) == 0 &&
        way.at(i).at(way.at(i).at(way.at(i).size() - 1)) == N - 1) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  long long r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  int N, M, a, b;
  cin >> N >> M;
  vector<vector<int>> way(N);
  for (size_t i = 0; i < M; i++) {
    cin >> a >> b;
    a--;
    b--;
    way.at(a).push_back(b);
    way.at(b).push_back(a);
  }
  for (size_t i = 0; i < N; i++) {
    sort(way.at(i).begin(), way.at(i).end());
    if (way.at(i).size() != 0 && way.at(i).at(0) == 0 &&
        way.at(i).at(way.at(i).size() - 1) == N - 1) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> A, B;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      B[b] = 1;
    if (b == n)
      A[a] = 1;
  }
  for (auto p : A) {
    for (auto q : B) {
      if (p.first == q.first) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> A, B;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      B[b] = 1;
    if (b == n)
      A[a] = 1;
  }
  for (auto p : A) {
    if (B[p.first] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  vector<int> a1;
  for (int i = 0; i < m; i++) {
    if (a[i] == 1) {
      a1.push_back(b[i]);
    }
  }
  vector<int> a2;
  for (int i = 0; i < m; i++) {
    if (b[i] == n) {
      a2.push_back(a[i]);
    }
  }

  sort(a1.begin(), a1.end());
  sort(a2.begin(), a2.end());

  while (1) {
    if (a1[0] == 0 || a2[0] == 0) {
      cout << "IMPOSSIBLE" << endl;
      break;
    }

    if (a1[0] == a2[0]) {
      cout << "POSSIBLE" << endl;
      break;
    }

    if (a1[0] > a2[0]) {
      a2.erase(a2.begin());
    } else {
      a1.erase(a1.begin());
    }
  }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  vector<int> a1;
  for (int i = 0; i < m; i++) {
    if (a[i] == 1) {
      a1.push_back(b[i]);
    }
  }
  vector<int> a2;
  for (int i = 0; i < m; i++) {
    if (b[i] == n) {
      a2.push_back(a[i]);
    }
  }

  sort(a1.begin(), a1.end());
  sort(a2.begin(), a2.end());

  while (1) {
    if (a1.size() == 0 || a2.size() == 0) {
      cout << "IMPOSSIBLE" << endl;
      break;
    }

    if (a1[0] == a2[0]) {
      cout << "POSSIBLE" << endl;
      break;
    }

    if (a1[0] > a2[0]) {
      a2.erase(a2.begin());
    } else {
      a1.erase(a1.begin());
    }
  }
  return 0;
}
Problem p03645 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  vector<ll> b(m);
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  bitset<200000> s;
  bitset<200000> g;

  for (ll i = 0; i < n; i++) {
    if (a[i] == 1) {
      s.set(b[i], 1);
    }
    if (b[i] == n) {
      g.set(a[i], 1);
    }
  }

  if ((s & g) != 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  vector<ll> b(m);
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  bitset<200000> s;
  bitset<200000> g;

  for (ll i = 0; i < m; i++) {
    if (a[i] == 1) {
      s.set(b[i], 1);
    }
    if (b[i] == n) {
      g.set(a[i], 1);
    }
  }

  if ((s & g) != 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}