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

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

#define _For(idx, from, to, inc, cmp)                                          \
  for (auto idx = (from); idx cmp(to); inc idx)
#define ForLE(idx, from, to) _For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) _For(idx, from, to, --, >=)
#define ForLT(idx, from, to) _For(idx, from, to, ++, <)
#define ForGT(idx, from, to) _For(idx, from, to, --, >)
#define For(idx, from, to) _For(idx, from, to, ++, <)

using u64 = uint64_t;
u64 MakePair(const int from, const int to) { return (u64(from) << 32) | to; }
#include <algorithm>
#include <unordered_set>
int main() {
  int NLand, NEdge;
  std::cin >> NLand >> NEdge;
  std::vector<int> beg, dst;
  For(i, 0, NEdge) {
    int e0, e1;
    std::cin >> e0 >> e1;
    if (e0 > e1)
      std::swap(e0, e1);
    if (e0 == 1)
      beg.push_back(e1);
    else if (e1 == NLand)
      dst.push_back(e0);
  }
  std::sort(dst.begin(), dst.end());
  const auto chk = [&]() {
    for (auto inter : beg) {
      const auto itr = std::lower_bound(dst.begin(), dst.end(), inter);
      if (*itr == inter)
        return true;
    }
    return false;
  };
  if (chk())
    std::cout << "POSSIBLE";
  else
    std::cout << "IMPOSSIBLE";
  std::cout << std::endl;
  return 0;
}

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

#define _For(idx, from, to, inc, cmp)                                          \
  for (auto idx = (from); idx cmp(to); inc idx)
#define ForLE(idx, from, to) _For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) _For(idx, from, to, --, >=)
#define ForLT(idx, from, to) _For(idx, from, to, ++, <)
#define ForGT(idx, from, to) _For(idx, from, to, --, >)
#define For(idx, from, to) _For(idx, from, to, ++, <)

using u64 = uint64_t;
u64 MakePair(const int from, const int to) { return (u64(from) << 32) | to; }
#include <algorithm>
#include <unordered_set>
int main() {
  int NLand, NEdge;
  std::cin >> NLand >> NEdge;
  std::vector<int> beg, dst;
  For(i, 0, NEdge) {
    int e0, e1;
    std::cin >> e0 >> e1;
    if (e0 > e1)
      std::swap(e0, e1);
    if (e0 == 1)
      beg.push_back(e1);
    else if (e1 == NLand)
      dst.push_back(e0);
  }
  std::sort(dst.begin(), dst.end());
  const auto chk = [&]() {
    for (auto inter : beg) {
      const auto itr = std::lower_bound(dst.begin(), dst.end(), inter);
      if (itr != dst.end() && *itr == inter)
        return true;
    }
    return false;
  };
  if (chk())
    std::cout << "POSSIBLE";
  else
    std::cout << "IMPOSSIBLE";
  std::cout << std::endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1 << 30)

/////////////////////////////////////////////////////////

void Main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> V(N);
  rep(i, 0, N) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  string res = "IMPOSSIBLE";
  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)
        res = "POSSIBLE";
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << std::fixed << std::setprecision(15);

  Main();
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1 << 30)

/////////////////////////////////////////////////////////

void Main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> V(N);
  rep(i, 0, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  string res = "IMPOSSIBLE";
  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)
        res = "POSSIBLE";
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << std::fixed << std::setprecision(15);

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> ab(N, vector<ll>(M));
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    ab[a - 1].push_back(b - 1);
  }
  for (auto aaa : ab[0]) {
    for (auto bbb : ab[aaa]) {
      if (bbb == N - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> ab(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    ab[a - 1].push_back(b - 1);
  }
  for (auto aaa : ab[0]) {
    for (auto bbb : ab[aaa]) {
      if (bbb == N - 1) {
        cout << "POSSIBLE" << 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<int> st;
  vector<int> go;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      st.push_back(b);
    if (b == N)
      go.push_back(a);
  }
  sort(st.begin(), st.end());
  sort(go.begin(), go.end());
  bool res = false;
  int j = 0, gosize = go.size();
  for (unsigned int i = 0; i < st.size() && !res; i++) {
    for (; j < gosize && go[j] <= st[i]; j++) {
      if (st[i] == go[j]) {
        res = true;
        break;
      }
    }
    j--;
  }
  if (res)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> st;
  vector<int> go;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      st.push_back(b);
    if (b == N)
      go.push_back(a);
  }
  sort(st.begin(), st.end());
  sort(go.begin(), go.end());
  bool res = false;
  int j = 0, gosize = go.size();
  for (unsigned int i = 0; i < st.size() && !res; i++) {
    for (; j < gosize && go[j] <= st[i]; j++) {
      if (st[i] == go[j]) {
        res = true;
        break;
      }
    }
    if (j > 0)
      j--;
  }
  if (res)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M, 200001);
  vector<int> B(M, -1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      A[i] = b;
    if (b == N)
      B[i] = a;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  for (int i = 0; i < M; i++) {
    if (A[i] == 200001)
      break;
    for (int j = M - 1; j >= 0; j--) {
      if (B[j] == -1 || B[j] < A[i])
        break;
      if (A[i] == B[j]) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M, 200001);
  vector<int> B(M, -1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      A[i] = b;
    if (b == N)
      B[i] = a;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  for (int i = 0; i < M; i++) {
    if (A[i] == 200001)
      break;
    if (binary_search(B.begin(), B.end(), A[i])) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define INF 1000000000000000
#define ll long long
using namespace std;
ll N;
struct edge {
  ll to, cost;
};
vector<edge> G[100005];
ll d[100005];
typedef pair<ll, ll> P;
ll dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + N, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    ll v = p.second;
    if (d[v] < p.first)
      continue;

    for (ll i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main() {
  ll M;
  cin >> N >> M;
  int a, b, c;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(edge{b, 1});
    G[b].push_back(edge{a, 1});
  }
  dijkstra(0);
  if (d[N - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define INF 1000000000000000
#define ll long long
using namespace std;
ll N;
struct edge {
  ll to, cost;
};
vector<edge> G[200005];
ll d[200005];
typedef pair<ll, ll> P;
ll dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + N, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    ll v = p.second;
    if (d[v] < p.first)
      continue;

    for (ll i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main() {
  ll M;
  cin >> N >> M;
  int a, b, c;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(edge{b, 1});
    G[b].push_back(edge{a, 1});
  }
  dijkstra(0);
  if (d[N - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(n);
  rep(i, m) {
    cin >> a[i].first >> a[i].second;
    a[i].first--, a[i].second--;
  }
  vector<bool> flag1(n, false);
  vector<bool> flag2(n, false);

  rep(i, m) {
    if (a[i].first == 0)
      flag1[a[i].second] = true;
    if (a[i].second == n - 1)
      flag2[a[i].first] = true;
  }
  rep(i, n) {
    if (flag1[i] && flag2[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(m);
  rep(i, m) {
    cin >> a[i].first >> a[i].second;
    a[i].first--, a[i].second--;
  }
  vector<bool> flag1(n, false);
  vector<bool> flag2(n, false);

  rep(i, m) {
    if (a[i].first == 0)
      flag1[a[i].second] = true;
    if (a[i].second == n - 1)
      flag2[a[i].first] = true;
  }
  rep(i, n) {
    if (flag1[i] && flag2[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  rep(i, n) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  vector<int> from_1(n, false);
  vector<int> to_n(n, false);
  rep(i, m) {
    if (a[i] == 0)
      from_1[b[i]] = true;
    if (b[i] == n - 1)
      to_n[a[i]] = true;
  }
  rep(i, n) {
    if (from_1[i] and to_n[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  vector<int> from_1(n, false);
  vector<int> to_n(n, false);
  rep(i, m) {
    if (a[i] == 0)
      from_1[b[i]] = true;
    if (b[i] == n - 1)
      to_n[a[i]] = true;
  }
  rep(i, n) {
    if (from_1[i] and to_n[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (Python)

Buggy submission (status: Runtime Error):
N, M = int(input())
set_a, set_b = set(), set()

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        set_a.add(b)
    if b == N:
        set_b.add(a)

if set_a & set_b:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Fixed submission:
N, M = map(int, input().split())
set_a, set_b = set(), set()

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        set_a.add(b)
    if b == N:
        set_b.add(a)

if set_a & set_b:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03645 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(M)]
    A = [b for a, b in AB if a == 1]
    B = [a for a, b in AB if b == N]

    result = "IMPOSSIBLE"
    for a in A:
        if a in B:
            result = "POSSIBLE"
    print(result)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    # AB = [list(map(int, input().split())) for _ in range(M)]
    from_1 = [False] * N
    to_N = [False] * N
    for _ in range(M):
        a, b = map(int, input().split())
        if a == 1:
            from_1[b - 1] = True
        elif b == N:
            to_N[a - 1] = True
    for i in range(1, N):
        if from_1[i] and to_N[i]:
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")


if __name__ == "__main__":
    main()
Problem p03645 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
first = {}
second = {}
for i in range(m):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        first.add(b[i])
    if b[i] == n:
        second.add(a[i])


ans = "IMPOSSIBLE"
if first & second:
    ans = "POSSIBLE"
print(ans)


Fixed submission:
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
first = set()
second = set()
for i in range(m):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        first.add(b[i])
    if b[i] == n:
        second.add(a[i])


ans = "IMPOSSIBLE"
if first & second:
    ans = "POSSIBLE"
print(ans)
Problem p03645 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = map(int, input().split())
teiki_1 = []
teiki_N = []
for _ in range(M):
    a, b = map(int, input().split())
    if a == 1 or b == 1:
        teiki_1.append(a if a != 1 else b)
    if a == N or b == N:
        teiki_N.append(a if a != N else b)
for num in sorted(teiki_1):
    if num in sorted(teiki_N):
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Fixed submission:
N, M = map(int, input().split())
teiki_1 = []
teiki_N = []
for _ in range(M):
    a, b = map(int, input().split())
    if a == 1 or b == 1:
        teiki_1.append(a if a != 1 else b)
    if a == N or b == N:
        teiki_N.append(a if a != N else b)
if len(set(teiki_1) & set(teiki_N)) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03645 (Python)

Buggy submission (status: Runtime Error):
import bisect

N, M = map(int, input().split())
start_to_middle = []
middle_to_end = []
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        start_to_middle.append(b)
    elif b == N:
        middle_to_end.append(a)
if not len(start_to_middle) or not len(middle_to_end):
    print("IMPOSSIBLE")
    exit()
middle_to_end.sort()
for middle in start_to_middle:
    idx = bisect.bisect_left(middle_to_end, middle)
    if middle_to_end[idx] == middle:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


Fixed submission:
import bisect

N, M = map(int, input().split())
start_to_middle = []
middle_to_end = []
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        start_to_middle.append(b)
    elif b == N:
        middle_to_end.append(a)
if not len(start_to_middle) or not len(middle_to_end):
    print("IMPOSSIBLE")
    exit()
middle_to_end.sort()
for middle in start_to_middle:
    idx = bisect.bisect_left(middle_to_end, middle)
    if idx < len(middle_to_end) and middle_to_end[idx] == middle:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
Problem p03645 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())
s1 = set()
s2 = set()

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        s1.add(b)
    if b == N:
        s2.add(a)

for x in s1:
    if s2.count(x) >= 1:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


Fixed submission:
N, M = map(int, input().split())
s1 = set()
s2 = set()

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        s1.add(b)
    if b == N:
        s2.add(a)

if len(s1.intersection(s2)) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03645 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(n);
  int i;
  for (i = 0; i < m; i++)
    cin >> a.at(i) >> b.at(i);
  vector<int> counta(n);
  vector<int> countb(n);
  for (i = 0; i < m; i++) {
    if (a.at(i) == 1)
      countb.at(b.at(i) - 1)++;
    if (b.at(i) == n)
      counta.at(a.at(i) - 1)++;
  }
  bool ok = false;
  for (i = 0; i < n; i++) {
    if (counta.at(i) >= 1 && countb.at(i) >= 1)
      ok = true;
  }
  if (ok)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  int i;
  for (i = 0; i < m; i++)
    cin >> a.at(i) >> b.at(i);
  vector<int> counta(n);
  vector<int> countb(n);
  for (i = 0; i < m; i++) {
    if (a.at(i) == 1)
      countb.at(b.at(i) - 1)++;
    if (b.at(i) == n)
      counta.at(a.at(i) - 1)++;
  }
  bool ok = false;
  for (i = 0; i < n; i++) {
    if (counta.at(i) >= 1 && countb.at(i) >= 1)
      ok = true;
  }
  if (ok)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03645 (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>> vec(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  sort(vec.begin(), vec.end());
  vector<int> one(0);
  int y = 0;
  for (int i = 0; i < M; i++) {
    if (vec.at(i).at(0) == 1) {
      one.push_back(vec.at(i).at(1));
    } else {
      y = i;
      break;
    }
  }
  sort(one.begin(), one.end());

  bool exist = false;
  int x = -1;
  for (int i = 0; i < one.size(); i++) {
    for (int j = y; j < M; j++) {
      if (vec.at(j).at(0) == one.at(i) && vec.at(j).at(1) == N) {
        exist = true;
        break;
      }
    }
  }

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  sort(vec.begin(), vec.end());
  vector<int> one(0);
  int y = 0;
  for (int i = 0; i < M; i++) {
    if (vec.at(i).at(0) == 1) {
      one.push_back(vec.at(i).at(1));
    } else {
      y = i;
      break;
    }
  }
  sort(one.begin(), one.end());

  bool exist = false;
  int x = -1;
  for (int i = 0; i < one.size(); i++) {
    for (int j = y; j < M; j++) {
      if (vec.at(j).at(0) == one.at(i) && vec.at(j).at(1) == N) {
        exist = true;
        break;
      }
      if (vec.at(j).at(0) > one.at(i)) {
        y = j - 1;
        break;
      }
    }
  }

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

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

int main(void) {
  ll n, m;
  cin >> n >> m;
  n--;
  vector<vector<ll>> ship(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ship[a].push_back(b);
  }
  for (int i = 0; i < ship[0].size(); i++) {
    vector<ll> f = ship[ship[0][i]];
    if (f.size() != 0 && *find(f.begin(), f.end(), n) == n) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

int main(void) {
  ll n, m;
  cin >> n >> m;
  n--;
  vector<vector<ll>> ship(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ship[a].push_back(b);
  }
  for (int i = 0; i < ship[0].size(); i++) {
    vector<ll> f = ship[ship[0][i]];
    if (f.size() != 0 && *find(f.begin(), f.end(), n) == n) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

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

#define rep(i, n, m) for (int(i) = (n); (i) < (m); (i)++)
#define rrep(i, n, m) for (int(i) = (n); (i) > (m); (i)--)
using ll = long long;
const ll MOD = 1e9 + 7;

void dfs(int p, int d, vector<int> &dis, vector<vector<int>> &lis) {

  dis[p] = d;
  rep(i, 0, lis[p].size()) {
    if (dis[lis[p][i]] > dis[p] + 1)
      dfs(lis[p][i], d + 1, dis, lis);
  }
}

int main() {

  int N, M, a, b;
  cin >> N >> M;

  vector<vector<int>> lis(N, vector<int>(0));

  rep(i, 0, M) {
    cin >> a >> b;
    a -= 1;
    b -= 1;
    lis[a].push_back(b);
    lis[b].push_back(a);
  }

  vector<int> dis(N, 1000000000);

  dfs(0, 0, dis, lis);

  // rep(i,0,N){
  //     cout << dis[i] << endl;
  // }

  if (dis[N - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

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

#define rep(i, n, m) for (int(i) = (n); (i) < (m); (i)++)
#define rrep(i, n, m) for (int(i) = (n); (i) > (m); (i)--)
using ll = long long;
const ll MOD = 1e9 + 7;

void dfs(int p, int d, vector<int> &dis, vector<vector<int>> &lis) {

  dis[p] = d;
  if (d < 2) {
    rep(i, 0, lis[p].size()) {
      if (dis[lis[p][i]] > dis[p] + 1)
        dfs(lis[p][i], d + 1, dis, lis);
    }
  }
}

int main() {

  int N, M, a, b;
  cin >> N >> M;

  vector<vector<int>> lis(N, vector<int>(0));

  rep(i, 0, M) {
    cin >> a >> b;
    a -= 1;
    b -= 1;
    lis[a].push_back(b);
    lis[b].push_back(a);
  }

  vector<int> dis(N, 1000000000);

  dfs(0, 0, dis, lis);

  // rep(i,0,N){
  //     cout << dis[i] << endl;
  // }

  if (dis[N - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03645 (C++)

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

using namespace std;

void bfs(vector<vector<int>> &edges, int node, vector<int> &state,
         vector<int> &dist) {
  queue<int> Q;
  Q.push(node);
  dist[node] = 0;
  while (!Q.empty()) {
    node = Q.front();
    Q.pop();
    if (dist[node] >= 3)
      break;
    for (int e : edges[node]) {
      if (state[e] == 0) {
        dist[e] = dist[node] + 1;
        Q.push(e);
      }
    }
    state[node] = 0;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> edges(N);
  vector<int> state(N), dist(N, -1);
  int a, b;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b;
    edges[--a].push_back(--b);
    edges[b].push_back(a);
  }

  bfs(edges, 0, state, dist);

  if (dist[N - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else
    cout << "IMPOSSIBLE" << endl;
}


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

using namespace std;

void bfs(vector<vector<int>> &edges, int node, vector<int> &state,
         vector<int> &dist) {
  queue<int> Q;
  Q.push(node);
  dist[node] = 0;
  while (!Q.empty()) {
    node = Q.front();
    Q.pop();
    if (dist[node] >= 2)
      break;
    for (int e : edges[node]) {
      if (state[e] == 0) {
        dist[e] = dist[node] + 1;
        Q.push(e);
      }
    }
    state[node] = 0;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> edges(N);
  vector<int> state(N), dist(N, -1);
  int a, b;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b;
    edges[--a].push_back(--b);
    edges[b].push_back(a);
  }

  bfs(edges, 0, state, dist);

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define s(x) scanf("%d", &x);
#define bug(x) printf("  %s = %d \n", #x, x);
#define mem(arr, x) memset(arr, x, sizeof arr);
const int maxn = 2e5 + 5;
typedef long long LL;
using namespace std;
vector<int> vec;
int f[maxn];

int main() {
  int N, M;
  while (scanf("%d%d", &N, &M)) {
    vec.clear();
    mem(f, 0) int a, b;
    for (int i = 1; i <= M; i++) {
      scanf("%d%d", &a, &b);
      if (b == N)
        f[a] = 1;
      if (a == 1)
        vec.push_back(b);
    }
    bool jud = 0;
    for (int i = 0; i < vec.size(); i++) {
      int v = vec[i];
      if (f[v]) {
        jud = true;
        break;
      }
    }
    if (jud)
      puts("POSSIBLE");
    else
      puts("IMPOSSIBLE");
  }
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define s(x) scanf("%d", &x);
#define bug(x) printf("  %s = %d \n", #x, x);
#define mem(arr, x) memset(arr, x, sizeof arr);
const int maxn = 2e5 + 5;
typedef long long LL;
using namespace std;
vector<int> vec;
int f[maxn];

int main() {
  int N, M;
  while (scanf("%d%d", &N, &M) != EOF) {
    vec.clear();
    mem(f, 0) int a, b;
    for (int i = 1; i <= M; i++) {
      scanf("%d%d", &a, &b);
      if (b == N)
        f[a] = 1;
      if (a == 1)
        vec.push_back(b);
    }
    bool jud = 0;
    for (int i = 0; i < vec.size(); i++) {
      int v = vec[i];
      if (f[v]) {
        jud = true;
        break;
      }
    }
    if (jud)
      puts("POSSIBLE");
    else
      puts("IMPOSSIBLE");
  }
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int main() {
  int n, m;
  std::cin >> n;
  std::cin >> m;
  std::vector<int> a, b;
  for (int i = 0; i < m; i++) {
    int x, y;
    std::cin >> x;
    std::cin >> y;
    a.push_back(x);
    b.push_back(y);
  }
  std::vector<int> start;
  std::vector<int> goal;
  for (int i = 0; i < m; i++) {
    if (a[i] == 1)
      start.push_back(b[i]);
    if (b[i] == n)
      goal.push_back(a[i]);
  }
  std::sort(start.begin(), start.end());
  std::sort(goal.begin(), goal.end());
  int p = 0;
  int q = 0;
  int ssize = (int)start.size();
  int gsize = (int)goal.size();

  while (true) {
    if (start[p] < goal[q])
      p = p + 1;
    else if (start[p] > goal[q])
      q = q + 1;
    else {
      std::cout << "POSSIBLE";
      return 0;
    }
    if (p + 1 > ssize || q + 1 > gsize) {
      break;
    }
  }
  std::cout << "IMPOSSIBLE";
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/


Fixed submission:
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int main() {
  int n, m;
  std::cin >> n;
  std::cin >> m;
  std::vector<int> a, b;
  for (int i = 0; i < m; i++) {
    int x, y;
    std::cin >> x;
    std::cin >> y;
    a.push_back(x);
    b.push_back(y);
  }
  std::vector<int> start;
  std::vector<int> goal;
  for (int i = 0; i < m; i++) {
    if (a[i] == 1)
      start.push_back(b[i]);
    if (b[i] == n)
      goal.push_back(a[i]);
  }
  if (start.size() == 0 || goal.size() == 0) {
    std::cout << "IMPOSSIBLE";
    return 0;
  }
  std::sort(start.begin(), start.end());
  std::sort(goal.begin(), goal.end());
  int p = 0;
  int q = 0;
  int ssize = (int)start.size();
  int gsize = (int)goal.size();

  while (true) {
    if (start[p] < goal[q])
      p = p + 1;
    else if (start[p] > goal[q])
      q = q + 1;
    else {
      std::cout << "POSSIBLE";
      return 0;
    }
    if (p + 1 > ssize || q + 1 > gsize) {
      break;
    }
  }
  std::cout << "IMPOSSIBLE";
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/
Problem p03645 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9 + 7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b %
// 2 ? a : 1) : 1; }
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int cost[200001];
vector<vector<int>> v(200001);
void dfs(int now) {
  for (int nxt : v[now]) {
    if (cost[nxt] <= cost[now] + 1)
      continue;
    cost[nxt] = cost[now] + 1;
    dfs(nxt);
  }
}

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

  fill_n(cost, 200001, inf);

  rep(i, m) {
    int a, b;
    cin >> a >> b;

    a--;
    b--;

    v[a].eb(b);
    v[b].eb(a);
  }

  cost[0] = 0;
  dfs(0);

  if (cost[n - 1] <= 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9 + 7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b %
// 2 ? a : 1) : 1; }
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int cost[200001];
vector<vector<int>> v(200001);
void dfs(int now) {
  if (cost[now] == 2)
    return;
  for (int nxt : v[now]) {
    if (cost[nxt] <= cost[now] + 1)
      continue;
    cost[nxt] = cost[now] + 1;
    dfs(nxt);
  }
}

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

  fill_n(cost, 200001, inf);

  rep(i, m) {
    int a, b;
    cin >> a >> b;

    a--;
    b--;

    v[a].eb(b);
    v[b].eb(a);
  }

  cost[0] = 0;
  dfs(0);

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

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> g(m);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[i] = make_pair(a, b);
  }

  sort(g.begin(), g.end());

  vector<ll> start, goal;

  rep(i, m) {
    if (g[i].first == 0) {
      start.push_back(g[i].second);
    }
    if (g[i].second == n - 1) {
      goal.push_back(g[i].first);
    }
  }

  sort(start.begin(), start.end());
  sort(goal.begin(), goal.end());

  ll s = start.size(), t = goal.size();
  rep(i, s) {
    rep(j, t) {
      if (start[i] == goal[j]) {
        cout << "POSSIBLE" << endl;
        return (0);
      }
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return (0);
}


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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> g(m);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[i] = make_pair(a, b);
  }

  sort(g.begin(), g.end());

  vector<ll> start, goal;

  rep(i, m) {
    if (g[i].first == 0) {
      start.push_back(g[i].second);
    }
    if (g[i].second == n - 1) {
      goal.push_back(g[i].first);
    }
  }

  sort(start.begin(), start.end());
  sort(goal.begin(), goal.end());

  ll s = start.size(), t = goal.size();
  rep(i, s) {
    ll x = start[i];
    if (binary_search(goal.begin(), goal.end(), x)) {
      cout << "POSSIBLE" << endl;
      return (0);
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return (0);
}
Problem p03645 (C++)

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

using namespace std;

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

  int n, m;
  cin >> n >> m;

  vector<int> a[n + 1];

  for (int i = 0; i < m; i++) {
    int j, k;
    cin >> j >> k;
    a[j].push_back(k);
    a[k].push_back(j);
  }

  bool yes = false;

  vector<int>::iterator it = find(a[1].begin(), a[1].end(), n);
  if (it != a[1].end()) {
    cout << "POSSIBLE" << endl;
    yes = true;
  } else {
    int size = a[1].size();
    for (vector<int>::iterator it = a[1].begin(); it != a[1].end(); it++) {
      vector<int>::iterator its = find(a[n].begin(), a[n].end(), *it);
      if (its != a[n].end()) {
        cout << "POSSIBLE" << endl;
        yes = true;
        break;
      }
    }
  }

  if (!yes)
    cout << "IMPOSSIBLE" << endl;

  return 0;
}


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

using namespace std;

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

  int n, m;
  cin >> n >> m;

  vector<int> a[n + 1];

  for (int i = 0; i < m; i++) {
    int j, k;
    cin >> j >> k;
    a[j].push_back(k);
    a[k].push_back(j);
  }

  bool yes = false;

  vector<int>::iterator it = find(a[1].begin(), a[1].end(), n);
  if (it != a[1].end()) {
    cout << "POSSIBLE" << endl;
    yes = true;
  } else {
    int size = a[1].size();
    sort(a[n].begin(), a[n].end());
    vector<int>::iterator it = a[1].begin();
    for (; size > 0; it++, size--) {
      if (binary_search(a[n].begin(), a[n].end(), *it)) {
        cout << "POSSIBLE" << endl;
        yes = true;
        break;
      }
    }
  }

  if (!yes)
    cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03645 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

int max(int a, int b) { return a > b ? a : b; }

int n, m;
vector<vector<int>> v(200010, vector<int>(0));
bool dfs(int x, int depth) {
  if (depth > 2)
    return false;
  if (depth == 2 && x == n)
    return true;

  REP(i, v[x].size()) {
    if (dfs(v[x][i], depth + 1))
      return true;
  }
  return false;
}

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

  int a, b;
  REP(i, m) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  cout << (dfs(1, 0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

int max(int a, int b) { return a > b ? a : b; }

int n, m;
vector<vector<int>> v(200010, vector<int>(0));
bool dfs(int x, int depth) {
  if (depth > 2)
    return false;
  if (depth == 2 && x == n)
    return true;

  REP(i, v[x].size()) {
    if (dfs(v[x][i], depth + 1))
      return true;
  }
  return false;
}

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

  int a, b;
  REP(i, m) {
    cin >> a >> b;
    if (a == 1 || b == n)
      v[a].push_back(b);
  }

  cout << (dfs(1, 0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}
Problem p03645 (C++)

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x, val) memset((x), (val), sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
#define N 111111

const int INF = 1 << 30;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> graph[N];
int dist[N];

int main() {
  int n, m, a, b;

  scanf("%d %d", &n, &m);

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

  queue<int> q;
  q.push(1);
  dist[1] = 1;

  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (u == n) {
      break;
    }

    for (auto v : graph[u]) {
      if (!dist[v]) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
  if ((dist[n] - 1) == 2)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");

  return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x, val) memset((x), (val), sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
#define N 211111

const int INF = 1 << 30;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> graph[N];
int dist[N];

int main() {
  int n, m, a, b;

  scanf("%d %d", &n, &m);

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

  queue<int> q;
  q.push(1);
  dist[1] = 1;

  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (u == n) {
      break;
    }

    for (auto v : graph[u]) {
      if (!dist[v]) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
  if ((dist[n] - 1) == 2)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");

  return 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

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

  vector<int> a(n), b(n);
  set<int> penul;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (b[i] == n)
      penul.insert(a[i]);
  }

  bool ans = false;
  for (int i = 0; i < m; i++) {
    if (a[i] == 1 && penul.count(b[i])) {
      ans = true;
      break;
    }
  }

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

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

  vector<int> a(m), b(m);
  set<int> penul;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (b[i] == n)
      penul.insert(a[i]);
  }

  bool ans = false;
  for (int i = 0; i < m; i++) {
    if (a[i] == 1 && penul.count(b[i])) {
      ans = true;
      break;
    }
  }

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

  return 0;
}
Problem p03645 (C++)

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

const int MOD = 1000000007;

// long long
using ll = long long;

// 出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

// begin() end()
#define all(x) (x).begin(), (x).end()

// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

// 最大公約数（ll）
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

// 素因数分解？
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> A(M, false), B(M, false);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      A.at(b - 1) = true;
    if (b == N)
      B.at(a - 1) = true;
  }

  REP(i, N) {
    if (A.at(i) == true && B.at(i) == true) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

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

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

const int MOD = 1000000007;

// long long
using ll = long long;

// 出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

// begin() end()
#define all(x) (x).begin(), (x).end()

// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

// 最大公約数（ll）
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

// 素因数分解？
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> A(N, false), B(N, false);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      A.at(b - 1) = true;
    if (b == N)
      B.at(a - 1) = true;
  }

  REP(i, N) {
    if (A.at(i) == true && B.at(i) == true) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<vector<int>> ship(m);
  int a = 0, b = 0;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    ship.at(a).push_back(b);
    ship.at(b).push_back(a);
  }
  for (int x : ship.at(0)) {
    for (int y : ship.at(x)) {
      if (y == n - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<vector<int>> ship(n);
  int a = 0, b = 0;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    ship.at(a).push_back(b);
    ship.at(b).push_back(a);
  }
  for (int x : ship.at(0)) {
    for (int y : ship.at(x)) {
      if (y == n - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  bool flag = false;
  bool *f, *g;
  f = (bool *)malloc(sizeof(N));
  g = (bool *)malloc(sizeof(N));
  int tempA, tempB;
  while (cin >> tempA >> tempB) {
    if (tempA == 1) {
      f[tempB] = true;
    }
    if (tempB == N) {
      g[tempA] = true;
    }
  }
  for (int i = 0; i < N; i++) {
    if (f[i] == true && g[i] == true) {
      flag = true;
    }
  }
  if (flag == true) {
    cout << "POSSIBLE";
  } else {
    cout << "IMPOSSIBLE";
  }

  free(f);
  free(g);
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  bool flag = false;
  bool *f, *g;
  f = (bool *)malloc(sizeof(bool) * N);
  g = (bool *)malloc(sizeof(bool) * N);
  int tempA, tempB;
  while (cin >> tempA >> tempB) {
    if (tempA == 1) {
      f[tempB] = true;
    }
    if (tempB == N) {
      g[tempA] = true;
    }
  }
  for (int i = 0; i < N; i++) {
    if (f[i] == true && g[i] == true) {
      flag = true;
    }
  }
  if (flag == true) {
    cout << "POSSIBLE";
  } else {
    cout << "IMPOSSIBLE";
  }

  free(f);
  free(g);
  return 0;
}