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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  long long K;
  cin >> K;
  vector<unsigned long long> res(50);
  REP(i, 50) { res[i] = 49; }
  REP(i, K) {
    res[i % 50] += 51;
    REP(j, 50) { res[j] -= 1; }
  }
  cout << 50 << endl;
  REP(i, 50) { cout << res[i] << " "; }
  cout << endl;
  // calc(res, 2);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  long long K;
  cin >> K;
  vector<unsigned long long> res(50);
  REP(i, 50) { res[i] = 49 + K / 50; }
  K %= 50;
  REP(i, K) {
    res[i % 50] += 51;
    REP(j, 50) { res[j] -= 1; }
  }
  cout << 50 << endl;
  REP(i, 50) { cout << res[i] << " "; }
  cout << endl;
  // calc(res, 2);
  return 0;
}
Problem p03646 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

#define _For(idx, from, to, inc, cmp)                                          \
  for (auto idx = (from); idx cmp(to); inc idx)
#define For(idx, from, to) _For(idx, from, to, ++, <)
using u64 = uint64_t;
using u64p = std::pair<u64, u64>;
using i64 = int64_t;
constexpr int NA = 50;
int main() {
  u64 n;
  std::cin >> n;

  const u64 div = n / NA;
  const u64 initial = (NA - 1) + div;
  std::vector<u64> ret(NA, initial);
  For(i, 0, n) {
    ret[i] += NA;
    For(j, 0, NA) {
      if (j != i) {
        ret[j] -= 1;
      }
    }
  }
  std::cout << NA << std::endl;
  For(i, 0, NA) {
    if (i != 0)
      std::cout << ' ';
    std::cout << ret[i];
  }
  std::cout << std::endl;
  return 0;
}

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

#define _For(idx, from, to, inc, cmp)                                          \
  for (auto idx = (from); idx cmp(to); inc idx)
#define For(idx, from, to) _For(idx, from, to, ++, <)
using u64 = uint64_t;
using u64p = std::pair<u64, u64>;
using i64 = int64_t;
constexpr int NA = 50;
int main() {
  u64 n;
  std::cin >> n;

  const u64 div = n / NA;
  const u64 initial = (NA - 1) + div;
  std::vector<u64> ret(NA, initial);
  n %= NA;
  For(i, 0, n) {
    ret[i] += NA;
    For(j, 0, NA) {
      if (j != i) {
        ret[j] -= 1;
      }
    }
  }
  std::cout << NA << std::endl;
  For(i, 0, NA) {
    if (i != 0)
      std::cout << ' ';
    std::cout << ret[i];
  }
  std::cout << std::endl;
  return 0;
}
Problem p03646 (C++)

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

long long k;
long long n, my, ans[50];
int main() {
  cin >> k;
  n = 50;
  my = k - k / 50;
  for (int i = 0; i < n; i++) {
    ans[i] = n + (k / n) - my - 1;
  }
  for (int i = 0; i < my; i++) {
    ans[i]++;
    ans[i] += my;
  }
  cout << 50 << endl;
  for (int i = 0; i < 49; i++) {
    cout << ans[i] << " ";
  }
  cout << ans[49] << endl;

  return 0;
}

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

long long k;
long long n, my, ans[50];
int main() {
  cin >> k;
  n = 50;
  my = k - (k / 50 * 50);
  for (int i = 0; i < n; i++) {
    ans[i] = n + (k / n) - my - 1;
  }
  for (int i = 0; i < my; i++) {
    ans[i]++;
    ans[i] += my;
  }
  cout << 50 << endl;
  for (int i = 0; i < 49; i++) {
    cout << ans[i] << " ";
  }
  cout << ans[49] << endl;

  return 0;
}
Problem p03646 (C++)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};

fastio _fast_io;

const int N = 50;
ll ans[N];
ll k;

int main() {
  cin >> k;
  ll a = k / N;
  ll b = k % N;
  ll c = N - b;
  fill(ans, ans + N, N + a - 1);
  for (int i = 0; i < b; ++i) {
    ++ans[i];
  }
  for (int i = b; i < N; ++b) {
    ans[i] -= b;
  }
  cout << N << endl;
  for (int i = 0; i < N; ++i) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};

fastio _fast_io;

const int N = 50;
ll ans[N];
ll k;

int main() {
  cin >> k;
  ll a = k / N;
  ll b = k % N;
  ll c = N - b;
  fill(ans, ans + N, N + a - 1);
  for (int i = 0; i < b; ++i) {
    ++ans[i];
  }
  for (int i = b; i < N; ++i) {
    ans[i] -= b;
  }
  cout << N << endl;
  for (int i = 0; i < N; ++i) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}
Problem p03646 (C++)

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

signed main() {
  int k;
  cin >> k;

  vi ans(50);

  if (k < 50)
    rep(i, 0, k) ans[i] = 50 - i;
  else {
    iota(all(ans), 1);
    reverse(all(ans));

    rep(i, 0, 50) ans[i] += k % 50 - 1;
    rep(i, 0, k / 50) ans[i]++;
  }

  cout << 50 << endl;
  rep(i, 0, 50) cout << ans[i] << " \n"[i == 49];

  return 0;
}


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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

signed main() {
  int k;
  cin >> k;

  vi ans(50);

  if (k < 50)
    rep(i, 0, k) ans[i] = 50 - i;
  else {
    iota(all(ans), 1);
    reverse(all(ans));

    rep(i, 0, 50) ans[i] += k / 50 - 1;
    rep(i, 0, k % 50) ans[i]++;
  }

  cout << 50 << endl;
  rep(i, 0, 50) cout << ans[i] << " \n"[i == 49];

  return 0;
}
Problem p03646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll K;
  cin >> K;
  if (K < 2) {
    cout << 2 << endl;
    cout << K + 1 << ' ' << 0 << endl;
  } else if (K >= 50) {
    cout << 50 << endl;
    ll div = K / 50;
    ll remain = K % 50;
    vector<ll> ans(50, 0);
    for (ll i = 0; i < 50; ++i) {
      ans.at(i) = i + div;
    }
    for (ll i = 0; i < 50; ++i) {
      if (i < remain) {
        ans.at(i) += 50 - remain + 1;
      } else {
        ans.at(i) -= remain;
      }
    }
    for (ll i = 0; i < 50; ++i) {
      cout << ans.at(i) << ' ';
    }
    cout << endl;
  } else {
    vector<ll> a(1);
    cout << a.at(1) << endl;
  }
}
// 100000000010000000


Fixed submission:
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll K;
  cin >> K;
  if (K < 2) {
    cout << 2 << endl;
    cout << K + 1 << ' ' << 0 << endl;
  } else if (K >= 50) {
    cout << 50 << endl;
    ll div = K / 50;
    ll remain = K % 50;
    vector<ll> ans(50, 0);
    for (ll i = 0; i < 50; ++i) {
      ans.at(i) = i + div;
    }
    for (ll i = 0; i < 50; ++i) {
      if (i < remain) {
        ans.at(i) += 50 - remain + 1;
      } else {
        ans.at(i) -= remain;
      }
    }
    for (ll i = 0; i < 50; ++i) {
      cout << ans.at(i) << ' ';
    }
    cout << endl;
  } else {
    cout << K << endl;
    for (ll i = 0; i < K; ++i) {
      cout << i + 1 << ' ';
    }
    cout << endl;
  }
}
// 100000000010000000
Problem p03646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  int n;
  cin >> n;
  vi d(n);
  rep(i, n) cin >> d[i];
  sort(d.rbegin(), d.rend());
  int mx = accumulate(all(d), 0);
  int mn = max(d[0] - (mx - d[0]), 0);
  cout << mx << endl;
  cout << mn << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  vll ans(50);
  ll k;
  cin >> k;
  ll x = k / 50;
  ll r = k % 50;
  rep(i, 50) {
    if (i < r)
      ans[i] = 49 + x + 51 - r;
    else
      ans[i] = 49 + x - r;
  }
  cout << 50 << endl;
  rep(i, 50) {
    if (i != 0)
      cout << " " << endl;
    cout << ans[i];
  }
}
Problem p03646 (C++)

Buggy submission (status: Runtime Error):
// atcoder/arc079/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto &i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template <typename P, typename Q>
ostream &operator<<(ostream &os, pair<P, Q> p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename P, typename Q>
istream &operator>>(istream &is, pair<P, Q> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  os << "(";
  each(i, v) os << i << ",";
  os << ")";
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  each(i, v) is >> i;
  return is;
}

template <typename T> inline T setmax(T &a, T b) { return a = std::max(a, b); }
template <typename T> inline T setmin(T &a, T b) { return a = std::min(a, b); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli k;
  while (cin >> k) {
    const int N = 50;
    vector<lli> a(N, (N - 1) + k / 50);
    for (int i = 0; i < k % N; ++i) {
      a[i] += N;
    }
    for (int i = k; i < N; ++i) {
      --a[i];
    }
    cout << a.size() << endl;
    for (int i = 0; i < a.size(); ++i) {
      if (i)
        cout << ' ';
      cout << a[i];
    }
    cout << endl;
  }

  return 0;
}


Fixed submission:
// atcoder/arc079/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto &i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template <typename P, typename Q>
ostream &operator<<(ostream &os, pair<P, Q> p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename P, typename Q>
istream &operator>>(istream &is, pair<P, Q> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  os << "(";
  each(i, v) os << i << ",";
  os << ")";
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  each(i, v) is >> i;
  return is;
}

template <typename T> inline T setmax(T &a, T b) { return a = std::max(a, b); }
template <typename T> inline T setmin(T &a, T b) { return a = std::min(a, b); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli k;
  while (cin >> k) {
    const int N = 50;
    vector<lli> a(N, (N - 1) + k / 50);
    for (int i = 0; i < k % N; ++i) {
      a[i] += N;
    }
    for (int i = 0; i < N; ++i) {
      a[i] -= k % N;
    }
    cout << a.size() << endl;
    for (int i = 0; i < a.size(); ++i) {
      if (i)
        cout << ' ';
      cout << a[i];
    }
    cout << endl;
  }

  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 1e5;
bool from1[N];
bool toN[N];
bool there_exists(int n) {
  for (int u = 1; u <= n; u++)
    if (from1[u] && toN[u])
      return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, m;
  cin >> n >> m;
  memset(from1, false, sizeof from1);
  memset(toN, false, sizeof toN);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (!(u <= v))
      swap(u, v);
    if (u == 1)
      from1[v] = true;
    if (v == n)
      toN[u] = true;
  }
  cout << (there_exists(n) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  cout << flush;
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 2e5;
bool from1[N];
bool toN[N];
bool there_exists(int n) {
  for (int u = 1; u <= n; u++)
    if (from1[u] && toN[u])
      return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, m;
  cin >> n >> m;
  memset(from1, false, sizeof from1);
  memset(toN, false, sizeof toN);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (!(u <= v))
      swap(u, v);
    if (u == 1)
      from1[v] = true;
    if (v == n)
      toN[u] = true;
  }
  cout << (there_exists(n) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  cout << flush;
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
// #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0')
      A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0')
      A = A * 10 + ct - '0';
  return A;
}

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

  int N = getint(), M = getint();
  bool A[100001] = {}, B[100001] = {};
  rep(i, M) {
    int a = getint(), b = getint();
    if (a == 1)
      A[b] = 1;
    if (b == N)
      B[a] = 1;
  }

  int ikeru = 0;
  rep1(i, N) if (A[i] && B[i]) ikeru = 1;

  if (ikeru)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");

  Would you please return 0;
}

Fixed submission:
// #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0')
      A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0')
      A = A * 10 + ct - '0';
  return A;
}

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

  int N = getint(), M = getint();
  bool A[200001] = {}, B[200001] = {};
  rep(i, M) {
    int a = getint(), b = getint();
    if (a == 1)
      A[b] = 1;
    if (b == N)
      B[a] = 1;
  }

  int ikeru = 0;
  rep1(i, N) if (A[i] && B[i]) ikeru = 1;

  if (ikeru)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");

  Would you please return 0;
}
Problem p03647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> Z(2);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      Z[0].push_back(b);
    if (b == 1)
      Z[0].push_back(a);
    if (a == N)
      Z[1].push_back(b);
    if (b == N)
      Z[1].push_back(a);
  }
  string ans = "IMPOSSIBLE";
  bool finish = false;
  sort(Z[0].begin(), Z[0].end());
  sort(Z[1].begin(), Z[1].end());
  for (int i = 0; i < Z[0].size(); i++) {
    for (int j = 0; j < Z[1].size(); j++) {
      if (Z[0][i] < Z[0][j])
        break;
      if (Z[0][i] == Z[1][j]) {
        ans = "POSSIBLE";
        finish = true;
        break;
      }
    }
    if (finish)
      break;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> Z(2);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      Z[0].push_back(b);
    if (b == 1)
      Z[0].push_back(a);
    if (a == N)
      Z[1].push_back(b);
    if (b == N)
      Z[1].push_back(a);
  }
  string ans = "IMPOSSIBLE";
  bool finish = false;
  sort(Z[0].begin(), Z[0].end());
  sort(Z[1].begin(), Z[1].end());
  for (int i = 0; i < Z[0].size(); i++) {
    auto IT = lower_bound(Z[1].begin(), Z[1].end(), Z[0][i]);
    int s = IT - Z[1].begin();
    //    cout<<"i:"<<i<<" s:"<<s<<endl;
    for (int j = s; j < Z[1].size(); j++) {
      if (Z[0][i] < Z[0][j])
        break;
      if (Z[0][i] == Z[1][j]) {
        ans = "POSSIBLE";
        finish = true;
        break;
      }
    }
    if (finish)
      break;
  }
  cout << ans << endl;
}
Problem p03647 (C++)

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

vector<int> graph[100005];
bool visited[100005];
int n, m, x, y;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  while (m--) {
    cin >> x >> y;
    graph[x].push_back(y);
  }
  queue<pair<int, int>> bfs;
  bfs.push(make_pair(1, 0));
  while (!bfs.empty()) {
    pair<int, int> p = bfs.front();
    visited[p.first] = true;
    bfs.pop();
    if (p.first == n) {
      cout << "POSSIBLE";
      return 0;
    }
    if (p.second == 2) {
      continue;
    }
    for (int i : graph[p.first]) {
      if (!visited[i]) {
        bfs.push(make_pair(i, p.second + 1));
      }
    }
  }
  cout << "IMPOSSIBLE";
}

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

vector<int> graph[200005];
bool visited[200005];
int n, m, x, y;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  while (m--) {
    cin >> x >> y;
    graph[x].push_back(y);
  }
  queue<pair<int, int>> bfs;
  bfs.push(make_pair(1, 0));
  while (!bfs.empty()) {
    pair<int, int> p = bfs.front();
    visited[p.first] = true;
    bfs.pop();
    if (p.first == n) {
      cout << "POSSIBLE";
      return 0;
    }
    if (p.second == 2) {
      continue;
    }
    for (int i : graph[p.first]) {
      if (!visited[i]) {
        bfs.push(make_pair(i, p.second + 1));
      }
    }
  }
  cout << "IMPOSSIBLE";
}
Problem p03647 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> voyages(n);
  for (int i = 0; i < m; i++) {
    vector<int> voyage(2);
    cin >> voyage[0] >> voyage[1];
    voyages[i] = voyage;
  }
  vector<int> points;
  for (int i = 0; i < m; i++) {
    if (voyages[i][0] == 1) {
      points.push_back(voyages[i][1]);
    } else if (voyages[i][1] == n) {
      points.push_back(voyages[i][0]);
    }
  }
  int points_size = points.size();
  sort(points.begin(), points.end());
  points.erase(unique(points.begin(), points.end()), points.end());
  int unique_points_size = points.size();
  if (points_size == unique_points_size) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << "POSSIBLE" << endl;
  }

  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> voyages(m);
  for (int i = 0; i < m; i++) {
    vector<int> voyage(2);
    cin >> voyage[0] >> voyage[1];
    voyages[i] = voyage;
  }
  vector<int> points;
  for (int i = 0; i < m; i++) {
    if (voyages[i][0] == 1) {
      points.push_back(voyages[i][1]);
    } else if (voyages[i][1] == n) {
      points.push_back(voyages[i][0]);
    }
  }
  int points_size = points.size();
  sort(points.begin(), points.end());
  points.erase(unique(points.begin(), points.end()), points.end());
  int unique_points_size = points.size();
  if (points_size == unique_points_size) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << "POSSIBLE" << endl;
  }

  return 0;
}
Problem p03647 (C++)

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

#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
template <typename T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}
template <typename T> bool chmin(T &a, const T &b) {
  return b < a ? (a = b, true) : false;
}
typedef long long ll;

int N, M;
const int MAX_N = 100000;
int b[MAX_N];

int main() {
  scanf("%d%d", &N, &M);
  FOR(i, 0, M) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    if (u > v)
      swap(u, v);
    if (u == 0)
      b[v] |= 1;
    if (v == N - 1)
      b[u] |= 2;
  }

  bool ans = false;
  FOR(i, 0, N) { ans |= b[i] == 3; }
  puts(ans ? "POSSIBLE" : "IMPOSSIBLE");

  return 0;
}


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

#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
template <typename T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}
template <typename T> bool chmin(T &a, const T &b) {
  return b < a ? (a = b, true) : false;
}
typedef long long ll;

int N, M;
const int MAX_N = 200000;
int b[MAX_N];

int main() {
  scanf("%d%d", &N, &M);
  FOR(i, 0, M) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    if (u > v)
      swap(u, v);
    if (u == 0)
      b[v] |= 1;
    if (v == N - 1)
      b[u] |= 2;
  }

  bool ans = false;
  FOR(i, 0, N) { ans |= b[i] == 3; }
  puts(ans ? "POSSIBLE" : "IMPOSSIBLE");

  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[100100], n, ans, temp, a, b, c, k, m, p, l, temp1, temp2;
vector<ll> v[100100];
int main() {
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    a--, b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 0; i < v[0].size(); i++) {
    if (v[0][i] == (n - 1)) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  for (int i = 0; i < v[0].size(); i++) {
    for (int j = 0; j < v[v[0][i]].size(); j++) {
      if (v[v[0][i]][j] == n - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[100100], n, ans, temp, a, b, c, k, m, p, l, temp1, temp2;
vector<ll> v[200200];
int main() {
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    a--, b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 0; i < v[0].size(); i++) {
    if (v[0][i] == (n - 1)) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  for (int i = 0; i < v[0].size(); i++) {
    for (int j = 0; j < v[v[0][i]].size(); j++) {
      if (v[v[0][i]][j] == n - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03647 (C++)

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

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int inf = 1e9 + 7;

int cnt, head[maxn];
ll dis[maxn];

struct Edge {
  int v;
  ll w;
  int next;
  bool operator<(const Edge &rhs) const { return w > rhs.w; }
} e[maxn];

void add(int u, int v, int value) {
  e[cnt].v = v;
  e[cnt].w = value;
  e[cnt].next = head[u];
  head[u] = cnt++;
}

void init() {
  cnt = 0;
  memset(head, -1, sizeof(head));
}

void dij(int s, int len) {
  priority_queue<Edge> pq;
  for (int i = 1; i <= len; i++)
    dis[i] = inf;
  bool vis[maxn];
  memset(vis, false, sizeof(vis));
  dis[s] = 0;
  pq.push((Edge){s, 0, 0});
  while (!pq.empty()) {
    Edge tmp = pq.top();
    pq.pop();
    if (vis[tmp.v])
      continue;
    vis[tmp.v] = true;
    for (int i = head[tmp.v]; ~i; i = e[i].next) {
      Edge u = e[i];
      if (dis[u.v] > dis[tmp.v] + u.w) {
        dis[u.v] = dis[tmp.v] + u.w;
        pq.push((Edge){u.v, dis[u.v], 0});
      }
    }
  }
}

int main() {
  int n, m, u, v, w;
  while (~scanf("%d%d", &n, &m)) {
    init();
    while (m--) {
      scanf("%d%d", &u, &v);
      w = 1;
      add(u, v, w);
      add(v, u, w);
    }
    dij(1, n);
    if (dis[n] > 2)
      puts("IMPOSSIBLE");
    else
      puts("POSSIBLE");
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int inf = 1e9 + 7;

int cnt, head[maxn];
ll dis[maxn];

struct Edge {
  int v;
  ll w;
  int next;
  bool operator<(const Edge &rhs) const { return w > rhs.w; }
} e[maxn << 2];

void add(int u, int v, int value) {
  e[cnt].v = v;
  e[cnt].w = value;
  e[cnt].next = head[u];
  head[u] = cnt++;
}

void init() {
  cnt = 0;
  memset(head, -1, sizeof(head));
}

void dij(int s, int len) {
  priority_queue<Edge> pq;
  for (int i = 1; i <= len; i++)
    dis[i] = inf;
  bool vis[maxn];
  memset(vis, false, sizeof(vis));
  dis[s] = 0;
  pq.push((Edge){s, 0, 0});
  while (!pq.empty()) {
    Edge tmp = pq.top();
    pq.pop();
    if (vis[tmp.v])
      continue;
    vis[tmp.v] = true;
    for (int i = head[tmp.v]; ~i; i = e[i].next) {
      Edge u = e[i];
      if (dis[u.v] > dis[tmp.v] + u.w) {
        dis[u.v] = dis[tmp.v] + u.w;
        pq.push((Edge){u.v, dis[u.v], 0});
      }
    }
  }
}

int main() {
  int n, m, u, v, w;
  while (~scanf("%d%d", &n, &m)) {
    init();
    while (m--) {
      scanf("%d%d", &u, &v);
      w = 1;
      add(u, v, w);
      add(v, u, w);
    }
    dij(1, n);
    if (dis[n] > 2)
      puts("IMPOSSIBLE");
    else
      puts("POSSIBLE");
  }
  return 0;
}
Problem p03647 (C++)

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

int N, M;
vi g[100010];
bool r[100010], r2[100010];

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

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].pb(b);
    g[b].pb(a);
  }

  for (int to : g[0]) {
    r[to] = 1;
  }

  for (int to : g[N - 1]) {
    r2[to] = 1;
  }

  bool ok = 0;
  rep(i, N) {
    if (r[i] && r2[i]) {
      ok = 1;
    }
  }

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

  return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

int N, M;
vi g[200010];
bool r[200010], r2[200010];

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

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].pb(b);
    g[b].pb(a);
  }

  for (int to : g[0]) {
    r[to] = 1;
  }

  for (int to : g[N - 1]) {
    r2[to] = 1;
  }

  bool ok = 0;
  rep(i, N) {
    if (r[i] && r2[i]) {
      ok = 1;
    }
  }

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

  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
const int N = 200005;
int len[N], nex[N], last[N], endd[N], tot, dis[N];
bool mark[N];
int n, m;
queue<int> q;
void add(int x, int y, int l) {
  tot++;
  nex[tot] = last[x];
  last[x] = tot;
  len[tot] = l;
  endd[tot] = y;
}
void spfa(int x) {
  int i, y, u;
  for (i = 1; i <= n; i++)
    dis[i] = 1e9;
  dis[x] = 0;
  mark[x] = 1;
  q.push(x);
  while (q.size()) {
    u = q.front();
    q.pop();
    mark[u] = false;
    for (i = last[u]; i; i = nex[i]) {
      int y = endd[i];
      if (dis[u] + len[i] < dis[y]) {
        dis[y] = dis[u] + len[i];
        if (!mark[y]) {
          q.push(y);
          mark[y] = true;
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  int i, j, k, x, y, l;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y, 1);
    add(y, x, 1);
  }
  spfa(1);
  if (dis[n] > 2)
    puts("IMPOSSIBLE");
  else
    puts("POSSIBLE");
}

Fixed submission:
#include <cstring>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
const int N = 1000005;
int len[N], nex[N], last[N], endd[N], tot, dis[N];
bool mark[N];
int n, m;
queue<int> q;
void add(int x, int y, int l) {
  tot++;
  nex[tot] = last[x];
  last[x] = tot;
  len[tot] = l;
  endd[tot] = y;
}
void spfa(int x) {
  int i, y, u;
  for (i = 1; i <= n; i++)
    dis[i] = 1e9;
  dis[x] = 0;
  mark[x] = 1;
  q.push(x);
  while (q.size()) {
    u = q.front();
    q.pop();
    mark[u] = false;
    for (i = last[u]; i; i = nex[i]) {
      int y = endd[i];
      if (dis[u] + len[i] < dis[y]) {
        dis[y] = dis[u] + len[i];
        if (!mark[y]) {
          q.push(y);
          mark[y] = true;
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  int i, j, k, x, y, l;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y, 1);
    add(y, x, 1);
  }
  spfa(1);
  if (dis[n] > 2)
    puts("IMPOSSIBLE");
  else
    puts("POSSIBLE");
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
vector<int> edge[200005];
int n, m, vis[200005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  queue<pair<int, int>> Q;
  Q.push(make_pair(1, 0));
  while (!Q.empty()) {
    pair<int, int> tmp = Q.front();
    Q.pop();
    if (tmp.second > 2)
      break;
    vis[tmp.first] = 1;
    for (vector<int>::iterator i = edge[tmp.first].begin();
         i != edge[tmp.first].end(); i++) {
      if (!vis[*i]) {
        Q.push(make_pair(*i, tmp.second + 1));
      }
    }
  }
  if (vis[n])
    return puts("POSSIBLE");
  puts("IMPOSSIBLE");
  return 0;
}

Fixed submission:
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
vector<int> edge[200005];
int n, m, vis[200005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  queue<pair<int, int>> Q;
  Q.push(make_pair(1, 0));
  while (!Q.empty()) {
    pair<int, int> tmp = Q.front();
    Q.pop();
    if (tmp.second > 2)
      break;
    vis[tmp.first] = 1;
    for (vector<int>::iterator i = edge[tmp.first].begin();
         i != edge[tmp.first].end(); i++) {
      if (!vis[*i]) {
        Q.push(make_pair(*i, tmp.second + 1));
      }
    }
  }
  if (vis[n])
    return printf("POSSIBLE\n"), 0;
  puts("IMPOSSIBLE");
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FOR(j, k, n) for (int j = k; j < (int)(n); j++)
#define MAXN 100000000000000000
#define newl printf("\n")
#define test(t)                                                                \
  int t;                                                                       \
  cin >> t;                                                                    \
  for (int tes = 0; tes < t; tes++)
#define fio                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
typedef long long int lli;
const int MM = 120000;
lli m, n, k, p1, p2, p3, p, f, a[MM];
string s, s1, s2;
set<lli> g[MM];
int main() {
  fio;
  // Have you solved the problem completely?
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p1 >> p2;
    g[p1 - 1].insert(p2 - 1);
    g[p2 - 1].insert(p1 - 1);
  }
  if (g[0].find(n - 1) != g[0].end()) {
    cout << "POSSIBLE";
    return 0;
  }
  for (lli u : g[0]) {
    if (g[u].find(n - 1) != g[u].end()) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FOR(j, k, n) for (int j = k; j < (int)(n); j++)
#define MAXN 100000000000000000
#define newl printf("\n")
#define test(t)                                                                \
  int t;                                                                       \
  cin >> t;                                                                    \
  for (int tes = 0; tes < t; tes++)
#define fio                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
typedef long long int lli;
const int MM = 220000;
lli m, n, k, p1, p2, p3, p, f, a[MM];
string s, s1, s2;
set<lli> g[MM];
int main() {
  fio;
  // Have you solved the problem completely?
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p1 >> p2;
    g[p1 - 1].insert(p2 - 1);
    g[p2 - 1].insert(p1 - 1);
  }
  if (g[0].find(n - 1) != g[0].end()) {
    cout << "POSSIBLE";
    return 0;
  }
  for (lli u : g[0]) {
    if (g[u].find(n - 1) != g[u].end()) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
bool visited[100];
int dis[100];
vector<int> g[100];
void DFS(int v, int dep) {
  visited[v] = true;
  dis[v] = dep;
  for (int i = 0; i < g[v].size(); i++) {
    if (!visited[g[v][i]])
      DFS(g[v][i], dep + 1);
  }
  return;
}

int main() {
  int n, e, u, v, source;
  scanf("%d%d", &n, &e);
  while (e--) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }

  DFS(1, 0);
  dis[n] == 2 ? puts("POSSIBLE") : puts("IMPOSSIBLE");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool visited[200009];
int dis[200009];
vector<int> g[200009];
void DFS(int v, int dep) {
  visited[v] = true;
  dis[v] = dep;
  for (int i = 0; i < g[v].size(); i++) {
    if (!visited[g[v][i]])
      DFS(g[v][i], dep + 1);
  }
  return;
}

int main() {
  int n, e, u, v, source;
  scanf("%d%d", &n, &e);
  while (e--) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }

  DFS(1, 0);
  dis[n] == 2 ? puts("POSSIBLE") : puts("IMPOSSIBLE");
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int N = 100005;
bool s[N], t[N];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    if (u == 1)
      s[v] = true;
    if (v == n)
      t[u] = true;
  }
  for (int i = 2; i < n; i++)
    if (s[i] && t[i]) {
      cout << "POSSIBLE\n";
      return 0;
    }
  cout << "IMPOSSIBLE\n";
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
const int N = 200005;
bool s[N], t[N];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    if (u == 1)
      s[v] = true;
    if (v == n)
      t[u] = true;
  }
  for (int i = 2; i < n; i++)
    if (s[i] && t[i]) {
      cout << "POSSIBLE\n";
      return 0;
    }
  cout << "IMPOSSIBLE\n";
  return 0;
}
Problem p03647 (C++)

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

#define MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

  ll a, b;
  map<ll, ll> mp;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;

    if (a == 1 || b == 1) {
      if (a == 1) {
        mp[b]++;
      } else {
        mp[a]++;
      }
    }
    if (a == N || b == N) {
      if (a == N) {
        mp[b]++;
      } else {
        mp[a]++;
      }
    }

    for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= 2) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

  ll a, b;
  map<ll, ll> mp;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;

    if (a == 1 || b == 1) {
      if (a == 1) {
        mp[b]++;
      } else {
        mp[a]++;
      }
    }
    if (a == N || b == N) {
      if (a == N) {
        mp[b]++;
      } else {
        mp[a]++;
      }
    }
  }
  for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
    if (it->second >= 2) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 5;

int has1[MAX_N];
int hasn[MAX_N];

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

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    if (u > v)
      swap(u, v);
    if (u == 1)
      has1[v] = 1;
    if (v == n)
      hasn[u] = 1;
  }

  for (int i = 2; i < n; i++) {
    if (has1[i] && hasn[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

const int MAX_N = 2e5 + 5;

int has1[MAX_N];
int hasn[MAX_N];

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

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    if (u > v)
      swap(u, v);
    if (u == 1)
      has1[v] = 1;
    if (v == n)
      hasn[u] = 1;
  }

  for (int i = 2; i < n; i++) {
    if (has1[i] && hasn[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n];
  map<int, int> mp;
  bool flag = false;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      mp[b[i]]++;
      if (mp[b[i]] == 2) {
        flag = true;
        break;
      }
    }
    if (b[i] == n) {
      mp[a[i]]++;
      if (mp[a[i]] == 2) {
        flag = true;
        break;
      }
    }
  }
  if (flag) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  map<int, int> mp;
  bool flag = false;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      mp[b[i]]++;
      if (mp[b[i]] == 2) {
        flag = true;
        break;
      }
    }
    if (b[i] == n) {
      mp[a[i]]++;
      if (mp[a[i]] == 2) {
        flag = true;
        break;
      }
    }
  }
  if (flag) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
using P = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

ll MOD = 1000000007;
ll INF = 1 << 30;
ll dp[110][100100];

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c, d;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (a == 0)
      c.push_back(b);
    if (b == 0)
      c.push_back(a);
    if (a == n - 1)
      d.push_back(b);
    if (b == n - 1)
      d.push_back(a);
  }
  rep(i, c.size()) {
    rep(j, d.size()) {
      if (c[i] == d[j]) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
using P = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

ll MOD = 1000000007;
ll INF = 1 << 30;
ll dp[110][100100];

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c, d;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (a == 0)
      c.push_back(b);
    if (b == 0)
      c.push_back(a);
    if (a == n - 1)
      d.push_back(b);
    if (b == n - 1)
      d.push_back(a);
  }
  set<int> st;
  rep(i, c.size()) st.insert(c[i]);
  rep(i, d.size()) st.insert(d[i]);
  if (c.size() + d.size() != st.size()) {
    cout << "POSSIBLE" << endl;
  } else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x & (-x)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define PI acos(-1.0)
#define LL long long
#define Inf (1LL << 62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
using namespace std;
const int mod = 1e9 + 7;
int head[Maxn << 1], k;
struct Edge {
  int e;
  int next;
} edge[Maxm];
void add(int s, int e) {
  edge[k].e = e;
  edge[k].next = head[s];
  head[s] = k++;
}
bool vis[Maxn];
bool judge(int n) {
  for (int i = head[1]; i != -1; i = edge[i].next) {
    int v = edge[i].e;
    vis[v] = true;
  }
  for (int i = head[n]; i != -1; i = edge[i].next) {
    int v = edge[i].e;
    if (vis[v])
      return true;
  }
  return false;
}
int main() {
  int n, m, u, v;
  // input;output;
  while (~scanf("%d%d", &n, &m)) {
    k = 0;
    memset(head, -1, sizeof(head));
    memset(vis, false, sizeof(vis));
    while (m--) {
      scanf("%d%d", &u, &v);
      add(u, v);
      add(v, u);
    }
    printf("%s\n", judge(n) ? "POSSIBLE" : "IMPOSSIBLE");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x & (-x)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define PI acos(-1.0)
#define LL long long
#define Inf (1LL << 62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
using namespace std;
const int mod = 1e9 + 7;
int head[Maxn << 1], k;
struct Edge {
  int e;
  int next;
} edge[Maxm];
void add(int s, int e) {
  edge[k].e = e;
  edge[k].next = head[s];
  head[s] = k++;
}
bool vis[Maxn << 1];
bool judge(int n) {
  for (int i = head[1]; i != -1; i = edge[i].next) {
    int v = edge[i].e;
    vis[v] = true;
  }
  for (int i = head[n]; i != -1; i = edge[i].next) {
    int v = edge[i].e;
    if (vis[v])
      return true;
  }
  return false;
}
int main() {
  int n, m, u, v;
  // input;output;
  while (~scanf("%d%d", &n, &m)) {
    k = 0;
    memset(head, -1, sizeof(head));
    memset(vis, false, sizeof(vis));
    while (m--) {
      scanf("%d%d", &u, &v);
      add(u, v);
      add(v, u);
    }
    printf("%s\n", judge(n) ? "POSSIBLE" : "IMPOSSIBLE");
  }
  return 0;
}