Problem p03389 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = (mod + 1) / 2;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
long double ABS(long double a) { return max(a, -a); }
int bfs[60][60][60];
int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  queue<pair<int, pair<int, int>>> Q;
  Q.push(make_pair(a, make_pair(b, c)));
  for (int i = 0; i < 60; i++)
    for (int j = 0; j < 60; j++)
      for (int k = 0; k < 60; k++)
        bfs[i][j][k] = -1;
  bfs[a][b][c] = 0;
  while (Q.size()) {
    int A = Q.front().first;
    int B = Q.front().second.first;
    int C = Q.front().second.second;
    Q.pop();
    if (A == B && B == C) {
      printf("%d\n", bfs[A][B][C]);
      return 0;
    }
    if (A + 2 < 60 && bfs[A + 2][B][C] == -1) {
      bfs[A + 2][B][C] = bfs[A][B][C] + 1;
      Q.push(make_pair(A + 2, make_pair(B, C)));
    }
    if (B + 2 < 60 && bfs[A][B + 2][C] == -1) {
      bfs[A][B + 2][C] = bfs[A][B][C] + 1;
      Q.push(make_pair(A, make_pair(B + 2, C)));
    }
    if (C + 2 < 60 && bfs[A][B][C + 2] == -1) {
      bfs[A][B][C + 2] = bfs[A][B][C] + 1;
      Q.push(make_pair(A, make_pair(B, C + 2)));
    }
    if (A + 1 < 60 && B + 1 < 60 && bfs[A + 1][B + 1][C] == -1) {
      bfs[A + 1][B + 1][C] = bfs[A][B][C] + 1;
      Q.push(make_pair(A + 1, make_pair(B + 1, C)));
    }
    if (A + 1 < 60 && C + 1 < 60 && bfs[A + 1][B + 1][C] == -1) {
      bfs[A + 1][B][C + 1] = bfs[A][B][C] + 1;
      Q.push(make_pair(A + 1, make_pair(B, C + 1)));
    }
    if (C + 1 < 60 && B + 1 < 60 && bfs[A][B + 1][C + 1] == -1) {
      bfs[A][B + 1][C + 1] = bfs[A][B][C] + 1;
      Q.push(make_pair(A, make_pair(B + 1, C + 1)));
    }
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = (mod + 1) / 2;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
long double ABS(long double a) { return max(a, -a); }
int bfs[60][60][60];
int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  queue<pair<int, pair<int, int>>> Q;
  Q.push(make_pair(a, make_pair(b, c)));
  for (int i = 0; i < 60; i++)
    for (int j = 0; j < 60; j++)
      for (int k = 0; k < 60; k++)
        bfs[i][j][k] = -1;
  bfs[a][b][c] = 0;
  while (Q.size()) {
    int A = Q.front().first;
    int B = Q.front().second.first;
    int C = Q.front().second.second;
    Q.pop();
    if (A == B && B == C) {
      printf("%d\n", bfs[A][B][C]);
      return 0;
    }
    if (A + 2 < 60 && bfs[A + 2][B][C] == -1) {
      bfs[A + 2][B][C] = bfs[A][B][C] + 1;
      Q.push(make_pair(A + 2, make_pair(B, C)));
    }
    if (B + 2 < 60 && bfs[A][B + 2][C] == -1) {
      bfs[A][B + 2][C] = bfs[A][B][C] + 1;
      Q.push(make_pair(A, make_pair(B + 2, C)));
    }
    if (C + 2 < 60 && bfs[A][B][C + 2] == -1) {
      bfs[A][B][C + 2] = bfs[A][B][C] + 1;
      Q.push(make_pair(A, make_pair(B, C + 2)));
    }
    if (A + 1 < 60 && B + 1 < 60 && bfs[A + 1][B + 1][C] == -1) {
      bfs[A + 1][B + 1][C] = bfs[A][B][C] + 1;
      Q.push(make_pair(A + 1, make_pair(B + 1, C)));
    }
    if (A + 1 < 60 && C + 1 < 60 && bfs[A + 1][B][C + 1] == -1) {
      bfs[A + 1][B][C + 1] = bfs[A][B][C] + 1;
      Q.push(make_pair(A + 1, make_pair(B, C + 1)));
    }
    if (C + 1 < 60 && B + 1 < 60 && bfs[A][B + 1][C + 1] == -1) {
      bfs[A][B + 1][C + 1] = bfs[A][B][C] + 1;
      Q.push(make_pair(A, make_pair(B + 1, C + 1)));
    }
  }
}