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

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

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

const int MAX_V = 1000;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

int 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));
      }
    }
  }
  return d[V - 1];
}

int main() {
  int E;
  int from, to;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    cin >> from >> to;
    G[from - 1].push_back(edge{to - 1, 1});
    G[to - 1].push_back(edge{from - 1, 1});
  }

  if (dijkstra(0) == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define INF (1 << 29)

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

const int MAX_V = 1000000;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

int 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));
      }
    }
  }
  return d[V - 1];
}

int main() {
  int E;
  int from, to;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    cin >> from >> to;
    G[from - 1].push_back(edge{to - 1, 1});
    G[to - 1].push_back(edge{from - 1, 1});
  }

  if (dijkstra(0) == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03645 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  int a[100001], b[100001];
  int c[100001]{0};
  int d[100001]{0};
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      c[b[i]] = 1;
    }
    if (b[i] == n) {
      d[a[i]] = 1;
    }
  }
  for (int i = 0; i <= n; i++) {
    if (c[i] == 1 && d[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int a[200001], b[200001];
  int c[200001]{0};
  int d[200001]{0};
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      c[b[i]] = 1;
    }
    if (b[i] == n) {
      d[a[i]] = 1;
    }
  }
  for (int i = 0; i <= n; i++) {
    if (c[i] == 1 && d[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

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

int main() {
  long n, m, x = 0, k = 1, l = 0;
  cin >> n >> m;
  long a[m], b[m];
  vector<long> v(400010, 0);
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      v.at(i) = b[i];
      x++;
    }
    if (b[i] == n) {
      v.at(i) = a[i];
      x++;
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < 400009; i++) {
    if (v.at(i) != v.at(i + 1)) {
      k++;
    }
    if (v.at(i) == 0) {
      l++;
    }
  }
  if (k + l == 400010)
    cout << "POSSIBLE" << endl;
  else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

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

int main() {
  long n, m, x = 0, k = 1, l = 0;
  cin >> n >> m;
  long a[m], b[m];
  vector<long> v(400010, 0);
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++) {
    if (a[i] == 1) {
      v.at(i) = b[i];
      x++;
    }
    if (b[i] == n) {
      v.at(i) = a[i];
      x++;
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < 400009; i++) {
    if (v.at(i) != v.at(i + 1)) {
      k++;
    }
    if (v.at(i) == 0) {
      l++;
    }
  }
  if (k + l == 400010)
    cout << "POSSIBLE" << endl;
  else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
// const int MAX = 200005;
const int MAX = 6;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
int N, M;
/* function */
void bfs() {
  vector<int> visited(MAX, -1);

  visited[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int from = q.front();
    q.pop();
    if (visited[from] >= 2)
      continue;
    for (int to : G[from]) {
      if (visited[to] != NIL)
        continue;
      visited[to] = visited[from] + 1;
      q.push(to);
    }
  }

  cout << ((visited[N - 1] == 1 || visited[N - 1] == 2) ? "POSSIBLE"
                                                        : "IMPOSSIBLE")
       << '\n';
}
/* main */
int main() {
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  bfs();
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 200005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
int N, M;
/* function */
void bfs() {
  vector<int> visited(MAX, -1);

  visited[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int from = q.front();
    q.pop();
    if (visited[from] >= 2)
      continue;
    for (int to : G[from]) {
      if (visited[to] != NIL)
        continue;
      visited[to] = visited[from] + 1;
      q.push(to);
    }
  }

  cout << ((visited[N - 1] == 1 || visited[N - 1] == 2) ? "POSSIBLE"
                                                        : "IMPOSSIBLE")
       << '\n';
}
/* main */
int main() {
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  bfs();
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
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];
  }

  for (int j = 0; j < M; j++) {
    if (b[j] == N) {
      for (int k = j; k < M; k--) {
        if (a[j] == b[k]) {
          if (a[k] == 1) {
            cout << "POSSIBLE" << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
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];
  }
  bool pos[N + 1] = {};
  for (int i = 0; i < M; i++) {
    if (a[i] == 1) {
      pos[b[i]] = true;
    }
  }
  for (int i = 0; i < M; i++) {
    if (pos[a[i]] == true) {
      if (b[i] == N) {
        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> A;
  vector<int> n;

  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (a == 1)
      A.push_back(b);
    else if (b == N)
      n.push_back(a);
  }
  if (M == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(A.begin(), A.end());
  sort(n.begin(), n.end());
  bool flag = false;
  for (int i = 0; i < A.size(); i++) {
    auto itr = lower_bound(n.begin(), n.end(), A[i]);
    if (*itr == A[i]) {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;

  vector<int> A;
  vector<int> n;

  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (a == 1)
      A.push_back(b);
    else if (b == N)
      n.push_back(a);
  }
  if (A.size() == 0 || n.size() == 0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(A.begin(), A.end());
  sort(n.begin(), n.end());
  bool flag = false;
  for (int i = 0; i < A.size(); i++) {
    auto itr = lower_bound(n.begin(), n.end(), A[i]);
    if (*itr == A[i]) {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}

// 実行部
void Main() {
  ll n, m;
  cin >> n >> m;
  vll s(n), g(n);
  rep(i, m) cin >> s[i] >> g[i];
  map<ll, ll> S;
  rep(i, m) if (s[i] == 1) S[g[i]]++;
  rep(i, m) if (g[i] == n && S.count(s[i])) fin("POSSIBLE");
  fin("IMPOSSIBLE");
}

// 前処理
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); // 高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}

// 実行部
void Main() {
  ll n, m;
  cin >> n >> m;
  ll s[200009], g[200009];
  rep(i, m) cin >> s[i] >> g[i];
  map<ll, ll> S;
  rep(i, m) if (s[i] == 1) S[g[i]]++;
  rep(i, m) if (g[i] == n && S.count(s[i])) fin("POSSIBLE");
  fin("IMPOSSIBLE");
}

// 前処理
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); // 高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/
Problem p03645 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> can_reach_from_1;
  vector<int> can_reach_to_n;
  vector<pair<int, int>> link;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    link.emplace_back(a, b);
    if (a == 1)
      can_reach_from_1.push_back(b);
    if (b == n)
      can_reach_to_n.push_back(a);
  }

  sort(can_reach_from_1.begin(), can_reach_from_1.end());
  sort(can_reach_to_n.begin(), can_reach_to_n.end());

  bool ans = false;
  for (int i = 0; i < m; i++) {
    ans = binary_search(can_reach_to_n.begin(), can_reach_to_n.end(),
                        can_reach_from_1[i]);
    if (ans)
      break;
  }

  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> can_reach_from_1;
  vector<int> can_reach_to_n;
  vector<pair<int, int>> link;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    link.emplace_back(a, b);
    if (a == 1)
      can_reach_from_1.push_back(b);
    if (b == n)
      can_reach_to_n.push_back(a);
  }

  sort(can_reach_from_1.begin(), can_reach_from_1.end());
  sort(can_reach_to_n.begin(), can_reach_to_n.end());

  bool ans = false;
  for (int i = 0; i < can_reach_from_1.size(); i++) {
    ans = binary_search(can_reach_to_n.begin(), can_reach_to_n.end(),
                        can_reach_from_1[i]);
    if (ans)
      break;
  }

  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define lowbit(x) (x & (-x))
#define max(x, y) (x > y ? x : y)
#define min(x, y) (x < y ? x : y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a, 0, sizeof(a)))
typedef long long ll;
vector<int> v[200006];
int n, m, x, y, vis[200006];
bool flag;
void bfs(int x, int y, int k) {
  if (x == y && k <= 2) {
    printf("POSSIBLE\n");
    flag = true;
    return;
  }
  if (k > 2)
    return;
  vis[x] = 1;
  for (int i = 0; i < v[x].size(); i++)
    bfs(v[x][i], y, k + 1);
  vis[x] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  flag = false;
  memset(vis, 0, sizeof(vis));
  while (m--) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  bfs(1, n, 0);
  if (!flag)
    printf("IMPOSSIBLE\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define lowbit(x) (x & (-x))
#define max(x, y) (x > y ? x : y)
#define min(x, y) (x < y ? x : y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a, 0, sizeof(a)))
typedef long long ll;
vector<int> v[200006];
int n, m, x, y, vis[200006];
bool flag;
void bfs(int x, int y, int k) {
  if (x == y && k <= 2) {
    printf("POSSIBLE\n");
    flag = true;
    return;
  }
  if (k > 2)
    return;
  vis[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    if (!vis[v[x][i]]) {
      vis[v[x][i]] = 1;
      bfs(v[x][i], y, k + 1);
      vis[v[x][i]] = 0;
    }
  }
  vis[x] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  flag = false;
  memset(vis, 0, sizeof(vis));
  while (m--) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  bfs(1, n, 0);
  if (!flag)
    printf("IMPOSSIBLE\n");
  return 0;
}
Problem p03645 (C++)

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

typedef long long ll;
int modulo = 1000000007; // 10^9 + 7

int main() {
  int N, M;
  cin >> N >> M;
  bool first[N + 1];  // 島１から島iに行けるかどうか
  bool second[N + 1]; // 島ｊから島Nに行けるかどうか
  for (int i = 0; i < M + 1; i++) {
    first[i] = false;
    second[i] = false;
  }

  for (int i = 0; i < M; i++) {
    int departure, destination;
    cin >> departure >> destination;
    if (departure == 1)
      first[destination] = true;
    if (destination == N)
      second[departure] = true;
  }
  int ans = 0;
  for (int i = 1; i < N + 1 && ans == 0; i++)
    ans += (first[i] * second[i]);

  if (ans >= 1)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
int modulo = 1000000007; // 10^9 + 7

int main() {
  int N, M;
  cin >> N >> M;
  bool first[N + 1];  // 島１から島iに行けるかどうか
  bool second[N + 1]; // 島ｊから島Nに行けるかどうか
  for (int i = 0; i < N + 1; i++) {
    first[i] = false;
    second[i] = false;
  }

  for (int i = 0; i < M; i++) {
    int departure, destination;
    cin >> departure >> destination;
    if (departure == 1)
      first[destination] = true;
    if (destination == N)
      second[departure] = true;
  }
  int ans = 0;
  for (int i = 1; i < N + 1 && ans == 0; i++)
    ans += (first[i] * second[i]);

  if (ans >= 1)
    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 fo(a, b) for (int a = 0; a < b; a++)
#define V vector
signed main() {
  int n, m;
  cin >> n >> m;
  V<int> a;
  fo(i, m) {
    int b, c;
    cin >> b >> c;
    if (b == 1)
      a[c]++;
    if (c == n)
      a[b] += 10;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 11) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fo(a, b) for (int a = 0; a < b; a++)
#define V vector
signed main() {
  int n, m;
  cin >> n >> m;
  V<int> a(n + 1);
  fo(i, m) {
    int b, c;
    cin >> b >> c;
    if (b == 1)
      a[c]++;
    if (c == n)
      a[b] += 10;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 11) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main() {
  vector<bool> s(20010); // 1とi
  vector<bool> t(20010); // iとn がつながってる
  bool ok = false;
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      s[b] = true;
    if (b == n)
      t[a] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == true && t[i] == true)
      ok = true;
  }
  if (ok)
    cout << "POSSIBLE" << endl;
  else
    cout << "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 ll long long
int main() {
  vector<bool> s(200100); // 1とi
  vector<bool> t(200100); // iとn がつながってる
  bool ok = false;
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      s[b] = true;
    if (b == n)
      t[a] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == true && t[i] == true)
      ok = true;
  }
  if (ok)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, x, y;
bool b[N], c[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (x == 1)
      b[y] = true;
    if (y == n)
      c[x] = true;
  }
  c[1] = true;
  b[n] = true;
  for (int i = 1; i <= n; i++)
    if (b[i] && c[i]) {
      puts("POSSIBLE");
      return 0;
    }
  puts("IMPOSSIBLE");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, x, y;
bool b[N], c[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (x == 1)
      b[y] = true;
    if (y == n)
      c[x] = true;
  }
  c[1] = true;
  b[n] = true;
  for (int i = 1; i <= n; i++)
    if (b[i] && c[i]) {
      puts("POSSIBLE");
      return 0;
    }
  puts("IMPOSSIBLE");
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
bool A[200001];
inline char tc() {
  static char fl[0], *A = fl, *B = fl;
  return A == B && (B = (A = fl) + fread(fl, 1, 1, stdin), A == B) ? EOF : *A++;
}
inline int read() {
  int a = 0;
  static char c;
  while ((c = tc()) < 48 || c > 57)
    ;
  while (c >= 48 && c <= 57)
    a = a * 10 + c - 48, c = tc();
  return a;
}
int main() {
  int n, m, a, b;
  n = read();
  m = read();
  while (m--) {
    a = read();
    b = read();
    if (a == 1) {
      if (A[b])
        return puts("POSSIBLE"), 0;
      A[b] = 1;
    }
    if (b == n) {
      if (A[a])
        return puts("POSSIBLE"), 0;
      A[a] = 1;
    }
  }
  puts("IMPOSSIBLE");
  return 0;
}

Fixed submission:
#include <cstdio>
bool A[200001];
inline char tc() {
  static char fl[1000], *A = fl, *B = fl;
  return A == B && (B = (A = fl) + fread(fl, 1, 1000, stdin), A == B) ? EOF
                                                                      : *A++;
}
inline int read() {
  int a = 0;
  static char c;
  while ((c = tc()) < 48 || c > 57)
    ;
  while (c >= 48 && c <= 57)
    a = a * 10 + c - 48, c = tc();
  return a;
}
int main() {
  int n, m, a, b;
  n = read();
  m = read();
  while (m--) {
    a = read();
    b = read();
    if (a == 1) {
      if (A[b])
        return puts("POSSIBLE"), 0;
      A[b] = 1;
    }
    if (b == n) {
      if (A[a])
        return puts("POSSIBLE"), 0;
      A[a] = 1;
    }
  }
  puts("IMPOSSIBLE");
  return 0;
}
Problem p03645 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  if (m == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  bool flag = false;
  vector<int> b, ans;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1) {
      b.push_back(y);
      flag = true;
    }
    if (y == n) {
      ans.push_back(x);
      flag = true;
    }
  }

  sort(ans.begin(), ans.end());
  sort(b.begin(), b.end());
  decltype(ans)::iterator v1 = unique(ans.begin(), ans.end());
  decltype(b)::iterator v2 = unique(b.begin(), b.end());
  ans.erase(v1, ans.end());
  b.erase(v2, b.end());

  if (flag) {
    for (int i = 0; i < b.size(); i++) {
      auto result = find(ans.begin(), ans.end(), b[i]);
      if (result != ans.end()) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
      if (i > 50000) {
        cout << "IMPOSSIBLE" << 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;
  if (m == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  bool flag = false;
  vector<int> b, ans;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1) {
      b.push_back(y);
      flag = true;
    }
    if (y == n) {
      ans.push_back(x);
      flag = true;
    }
  }

  sort(ans.begin(), ans.end());
  sort(b.begin(), b.end());
  decltype(ans)::iterator v1 = unique(ans.begin(), ans.end());
  decltype(b)::iterator v2 = unique(b.begin(), b.end());
  ans.erase(v1, ans.end());
  b.erase(v2, b.end());

  if (flag) {
    for (int i = 0; i < b.size(); i++) {
      auto result = find(ans.begin(), ans.end(), b[i]);
      if (result != ans.end()) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
      if (i > 25000) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
      }
    }
  }

  cout << "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;

  vector<vector<int>> x(M + 1);

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

  for (auto a : x[1]) {
    for (auto b : x[a]) {
      if (b == N) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

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

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

  vector<vector<int>> x(N + 1);

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

  for (auto a : x[1]) {
    for (auto b : x[a]) {
      if (b == N) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m, 0);
  vector<int> e(m, 0);
  for (int i = 0; i < m; i++)
    cin >> s[i] >> e[i];
  // sort(s.begin(), s.end());
  vector<int> number_m1;
  vector<int> number_m2;
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && e[i] != n) {
      number_m1.push_back(e[i]);
    }
    if (e[i] == n && s[i] != 1) {
      number_m2.push_back(s[i]);
    }
  }

  // sort(number_m1.begin(), number_m1.end());
  // sort(number_m2.begin(), number_m2.end());

  // int p = min(, number_m2.size());
  int a[m];
  for (int i = 0; i < m; i++)
    a[i] = 0;
  // fill_n(a, m, 0);

  // cout << number_m1.size() << endl;
  // cout << number_m2.size() << endl;
  for (int i = 0; i < number_m1.size(); i++) {
    a[number_m1[i] - 1]++;
    // cout << number_m1[i] << endl;
  }
  for (int i = 0; i < number_m2.size(); i++) {
    a[number_m2[i] - 1]++;
    // cout << number_m2[i] << endl;
  }
  for (int i = 0; i < m; i++) {
    // cout << a[i] << endl;
    if (a[i] > 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m, 0);
  vector<int> e(m, 0);
  for (int i = 0; i < m; i++)
    cin >> s[i] >> e[i];
  // sort(s.begin(), s.end());
  vector<int> number_m1;
  vector<int> number_m2;

  if (m == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && e[i] != n) {
      number_m1.push_back(e[i]);
    }
    if (e[i] == n && s[i] != 1) {
      number_m2.push_back(s[i]);
    }
  }

  // sort(number_m1.begin(), number_m1.end());
  // sort(number_m2.begin(), number_m2.end());

  // int p = min(, number_m2.size());
  int a[m];
  for (int i = 0; i < m; i++)
    a[i] = 0;
  // fill_n(a, m, 0);

  // cout << number_m1.size() << endl;
  // cout << number_m2.size() << endl;
  for (int i = 0; i < number_m1.size(); i++) {
    a[number_m1[i] - 1]++;
    // cout << number_m1[i] << endl;
  }
  for (int i = 0; i < number_m2.size(); i++) {
    a[number_m2[i] - 1]++;
    // cout << number_m2[i] << endl;
  }
  for (int i = 0; i < m; i++) {
    // cout << a[i] << endl;
    if (a[i] > 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<int> c;
  vector<int> d;
  rep(i, n) {
    if (b[i] == n)
      c.pb(a[i]);
    if (a[i] == 1)
      d.pb(b[i]);
  }
  if (c.size() == 0 || d.size() == 0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  rep(i, d.size()) {
    int l = 0, r = c.size() - 1;
    if (c[l] == d[i] || c[r] == d[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (c[mid] == d[i]) {
        cout << "POSSIBLE" << endl;
        return 0;
      } else if (c[mid] < d[i])
        l = mid;
      else
        r = mid;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<int> c;
  vector<int> d;
  rep(i, m) {
    if (b[i] == n)
      c.pb(a[i]);
    if (a[i] == 1)
      d.pb(b[i]);
  }
  if (c.size() == 0 || d.size() == 0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  rep(i, d.size()) {
    int l = 0, r = c.size() - 1;
    if (c[l] == d[i] || c[r] == d[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (c[mid] == d[i]) {
        cout << "POSSIBLE" << endl;
        return 0;
      } else if (c[mid] < d[i])
        l = mid;
      else
        r = mid;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M;
vector<vector<int>> graph(200001);
bitset<200001> bit;

void rec(int corrent = 1, int count = 0) {
  if (corrent == N && count == 2) {
    printf("POSSIBLE\n");
    exit(0);
  }
  for (int i = 0; i < graph[corrent].size(); ++i) {
    int next = graph[corrent][i];
    if (!bit[next]) {
      bit[next] = true;
      rec(next, count + 1);
      bit[next] = false;
    }
  }
  return;
}

int main(void) {

  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    graph[a].push_back(b), graph[b].push_back(a);
  }

  bit[1] = true;
  rec();
  printf("IMPOSSIBLE\n");

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M;
vector<vector<int>> graph(200001);
bitset<200001> bit;

void rec(int corrent = 1, int count = 0) {

  if (count > 2)
    return;
  if (corrent == N && count == 2) {
    printf("POSSIBLE\n");
    exit(0);
  }
  for (int i = 0; i < graph[corrent].size(); ++i) {
    int next = graph[corrent][i];
    if (!bit[next]) {
      bit[next] = true;
      rec(next, count + 1);
      bit[next] = false;
    }
  }
  return;
}

int main(void) {

  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    graph[a].push_back(b), graph[b].push_back(a);
  }

  bit[1] = true;
  rec();
  printf("IMPOSSIBLE\n");

  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, m, vis1[300000], vis2[300000], a, b, i;
int main() {
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    if (a == 1) {
      vis1[b] = 1;
    }
    if (b == 1) {
      vis1[a] = 1;
    }
    if (a == n) {
      vis2[b] = 1;
    }
    if (b == n) {
      vis2[a] = 1;
    }
  }
  for (i = 0; i <= 300000; i++) {
    if (vis1[i] == 1 && vis2[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m, vis1[300003], vis2[300003], a, b, i;
int main() {
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    if (a == 1) {
      vis1[b] = 1;
    }
    if (b == 1) {
      vis1[a] = 1;
    }
    if (a == n) {
      vis2[b] = 1;
    }
    if (b == n) {
      vis2[a] = 1;
    }
  }
  for (i = 0; i <= 300000; i++) {
    if (vis1[i] == 1 && vis2[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;
signed main() {

  int n, m, a[111111], b[111111];
  cin >> n >> m;
  set<int> s;
  int count = 0;
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      s.insert(b[i]);
      count++;
    }
    if (b[i] == n) {
      s.insert(a[i]);
      count++;
    }
  }
  if (count != s.size())
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;
signed main() {

  int n, m, a[111111 * 2], b[111111 * 2];
  cin >> n >> m;
  set<int> s;
  int count = 0;
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      s.insert(b[i]);
      count++;
    }
    if (b[i] == n) {
      s.insert(a[i]);
      count++;
    }
  }
  if (count != s.size())
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

vector<vector<int>> input(2000001);
int N, M;

int main() {
  cin >> N >> M;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    input[a].pb(b);
  }
  int flag = 0;
  REP(i, 200001) {
    REP(j, input[i].size()) {
      if (count(input[input[1][i]].begin(), input[input[1][i]].end(), N) > 0) {
        flag = 1;
      }
    }
  }
  if (flag) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

vector<vector<int>> input(2000001);
int N, M;

int main() {
  cin >> N >> M;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    input[a].pb(b);
  }
  int flag = 0;
  REP(i, input[1].size()) {
    if (count(input[input[1][i]].begin(), input[input[1][i]].end(), N) > 0) {
      flag = 1;
    }
  }
  if (flag) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03645 (C++)

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

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

  bool h1[100010], h2[100010];
  memset(h1, 0, sizeof(h1));
  memset(h2, 0, sizeof(h2));

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      h1[b] = true;
    else if (b == n)
      h2[a] = true;
  }
  bool flag = false;
  rep(i, n) {
    if (h1[i] && h2[i])
      flag = true;
  }
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

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

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

  bool h1[200010], h2[200010];
  memset(h1, 0, sizeof(h1));
  memset(h2, 0, sizeof(h2));

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      h1[b] = true;
    else if (b == n)
      h2[a] = true;
  }
  bool flag = false;
  rep(i, n) {
    if (h1[i] && h2[i])
      flag = true;
  }
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_M = 200005;
int main() {
  int N, M;
  cin >> N >> M;
  int a[MAX_M], b[MAX_M];
  vector<int> cand;
  vector<int> cand2;
  bool flag1;
  flag1 = false;
  bool flag2;
  flag2 = false;
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      cand.push_back(b[i]);
      flag1 = true;
    }
    if (b[i] == N) {
      cand2.push_back(a[i]);
      flag2 = true;
    }
  }
  if (flag1)
    sort(cand.begin(), cand.end());
  if (flag2)
    sort(cand2.begin(), cand2.end());
  int j = 0;
  int i = 0;
  int lim = cand.size();
  int lim2 = cand2.size();
  if (lim == 0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  while (i <= lim && j <= lim2) {
    // cout << cand[i] << " " << cand2[j];
    if (cand[i] == cand2[j]) {
      cout << "POSSIBLE" << endl;
      return 0;
    } else if (cand[i] > cand2[j]) {
      j++;
    } else {
      i++;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_M = 200005;
int main() {
  int N, M;
  cin >> N >> M;
  int a[MAX_M], b[MAX_M];
  vector<int> cand;
  vector<int> cand2;
  bool flag1;
  flag1 = false;
  bool flag2;
  flag2 = false;
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) {
      cand.push_back(b[i]);
      flag1 = true;
    }
    if (b[i] == N) {
      cand2.push_back(a[i]);
      flag2 = true;
    }
  }
  if (flag1)
    sort(cand.begin(), cand.end());
  if (flag2)
    sort(cand2.begin(), cand2.end());
  int j = 0;
  int i = 0;
  int lim = cand.size();
  int lim2 = cand2.size();
  if (lim == 0 || lim2 == 0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  while (i <= lim && j <= lim2) {
    // cout << cand[i] << " " << cand2[j];
    if (cand[i] == cand2[j]) {
      cout << "POSSIBLE" << endl;
      return 0;
    } else if (cand[i] > cand2[j]) {
      j++;
    } else {
      i++;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03646 (C++)

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

#define rep(i, n) for (i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {
  ll i, j;
  ll k;
  cin >> k;
  if (k < 50) {
    ll n = k;
    vector<ll> a(n);
    for (i = 0; i < n; ++i) {
      a.at(i) = i;
    }
    for (i = 0; i < k; ++i) {
      rep(j, n) {
        if (j == i)
          a.at(j) += n;
        else
          --a.at(j);
      }
    }
    cout << n << endl;
    for (i = 0; i < n - 1; ++i) {
      cout << a.at(i) << " ";
    }
    cout << a.at(i) << endl;
    return 0;
  }
  ll n = 50;
  vector<ll> a(n);
  for (i = 0; i < n; ++i) {
    a.at(i) = i;
  }
  ll m = k / n;
  k %= n;
  for (i = 0; i < n; ++i) {
    a.at(i) += m;
  }
  for (i = 0; i < k; ++i) {
    rep(j, n) {
      if (j == i)
        a.at(j) += n;
      else
        --a.at(j);
    }
  }
  cout << n << endl;
  for (i = 0; i < n - 1; ++i) {
    cout << a.at(i) << " ";
  }
  cout << a.at(i) << endl;
  return 0;
}

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

#define rep(i, n) for (i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {
  ll i, j;
  ll k;
  cin >> k;
  if (k == 0) {
    cout << 2 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  } else if (k == 1) {
    cout << 2 << endl;
    cout << 2 << " " << 0 << endl;
    return 0;
  }
  if (k < 50) {
    ll n = k;
    vector<ll> a(n);
    for (i = 0; i < n; ++i) {
      a.at(i) = i;
    }
    for (i = 0; i < k; ++i) {
      rep(j, n) {
        if (j == i)
          a.at(j) += n;
        else
          --a.at(j);
      }
    }
    cout << n << endl;
    for (i = 0; i < n - 1; ++i) {
      cout << a.at(i) << " ";
    }
    cout << a.at(i) << endl;
    return 0;
  }
  ll n = 50;
  vector<ll> a(n);
  for (i = 0; i < n; ++i) {
    a.at(i) = i;
  }
  ll m = k / n;
  k %= n;
  for (i = 0; i < n; ++i) {
    a.at(i) += m;
  }
  for (i = 0; i < k; ++i) {
    rep(j, n) {
      if (j == i)
        a.at(j) += n;
      else
        --a.at(j);
    }
  }
  cout << n << endl;
  for (i = 0; i < n - 1; ++i) {
    cout << a.at(i) << " ";
  }
  cout << a.at(i) << endl;
  return 0;
}
Problem p03646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<P> vpl;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1 << 30;
const ll linf = 1LL << 62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
  ll k;
  cin >> k;
  ll q = k / 50;
  ll r = k % 50;
  vl a(50);
  rep(i, r) a[i] = 50;
  REP(i, r, 50) a[i] = 49 - r;
  rep(i, k) a[i] += q;
  puts("50");
  rep(i, 50) cout << a[i] << " ";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<P> vpl;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1 << 30;
const ll linf = 1LL << 62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
  ll k;
  cin >> k;
  ll q = k / 50;
  ll r = k % 50;
  vl a(50);
  rep(i, r) a[i] = 50;
  REP(i, r, 50) a[i] = 49 - r;
  rep(i, 50) a[i] += q;
  puts("50");
  rep(i, 50) cout << a[i] << " ";
}
Problem p03646 (C++)

Buggy submission (status: Runtime Error):

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  REP(i, v.size()) {
    if (i)
      os << endl;
    os << v[i];
  }
  return os;
}

int main() {
  ll k;
  vector<ll> v(50);

  cin >> k;

  REP(i, 50) { v[i] = i; }

  ll x = k / 50;
  ll y = k - x;

  REP(i, 50) { v[i] += x; }

  REP(i, y) {
    v[i] += 50;
    REP(j, 50) {
      if (i != j) {
        v[j]--;
      }
    }
  }

  cout << 50 << endl;
  cout << v << endl;
}

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  REP(i, v.size()) {
    if (i)
      os << endl;
    os << v[i];
  }
  return os;
}

int main() {
  ll k;
  vector<ll> v(50);

  cin >> k;

  REP(i, 50) { v[i] = i; }

  ll x = k / 50;
  ll y = k - x * 50;

  REP(i, 50) { v[i] += x; }

  REP(i, y) {
    v[i] += 50;
    REP(j, 50) {
      if (i != j) {
        v[j]--;
      }
    }
  }

  cout << 50 << endl;
  cout << v << endl;
}