Problem p02386 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>
#include <string>
using namespace std;

class Dice {
private:
  int right, wrong;
  int N, E, W, S;
  int tmp1, tmp2;

public:
  Dice() : right(0), wrong(0), N(0), E(0), W(0), S(0){};
  Dice(int ri, int wr, int n, int e, int w, int s)
      : right(ri), wrong(wr), N(n), E(e), W(w), S(s){};
  void SetDice(int, int, int, int, int, int);
  int ShowRight() { return right; }
  int ShowWrong() { return wrong; }
  int ShowN() { return N; }
  int ShowE() { return E; }
  int ShowW() { return W; }
  int ShowS() { return S; }
  void goN();
  void goE();
  void goW();
  void goS();
};

void Dice::SetDice(int ri, int wr, int n, int e, int w, int s) {
  right = ri;
  wrong = wr;
  N = n;
  S = s;
  W = w;
  E = e;
}
void Dice::goN() {
  tmp1 = N;
  tmp2 = S;
  N = wrong;
  S = right;
  right = tmp1;
  wrong = tmp2;
}
void Dice::goE() {
  tmp1 = E;
  tmp2 = W;
  E = wrong;
  W = right;
  right = tmp1;
  wrong = tmp2;
}
void Dice::goW() {
  tmp1 = W;
  tmp2 = E;
  W = wrong;
  E = right;
  right = tmp1;
  wrong = tmp2;
}
void Dice::goS() {
  tmp1 = S;
  tmp2 = N;
  S = wrong;
  N = right;
  right = tmp1;
  wrong = tmp2;
}

int main() {
  int label1[6];
  int label2[6];
  Dice dice[100];

  int n;
  int a, b;
  int flag = 0;
  int OK_flag = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++)
      cin >> label1[j];
    dice[i].SetDice(label1[0], label1[5], label1[1], label1[3], label1[2],
                    label1[4]);
  }

  for (int p = 0; p < n - 1; p++) {
    for (int q = p + 1; q < n; q++) {

      for (int j = 0; j < 6; j++) {
        for (int i = 0; i < 4; i++) {
          flag = 0;
          if (dice[p].ShowRight() != dice[q].ShowRight())
            flag = 1;
          if (dice[p].ShowWrong() != dice[q].ShowWrong())
            flag = 1;
          if (dice[p].ShowN() != dice[q].ShowN())
            flag = 1;
          if (dice[p].ShowE() != dice[q].ShowE())
            flag = 1;
          if (dice[p].ShowW() != dice[q].ShowW())
            flag = 1;
          if (dice[p].ShowS() != dice[q].ShowS())
            flag = 1;
          if (flag == 0)
            OK_flag = 1; //\\u5168\\u304f\\u540c\\u3058\\u306e\\u3068\\u304d=1
          dice[q].goS();
          dice[q].goW();
          dice[q].goN();
        }
        if (j == 0 || j == 1)
          dice[q].goN();
        else if (j == 2)
          dice[q].goE();
        else if (j == 3 || j == 4)
          dice[q].goN();
      }
    }
  }
  if (OK_flag == 0)
    cout << "Yes\\n"; //\\u3059\\u3079\\u3066\\u304c\\u7570\\u306a\\u308b\\u3068\\u304d
  else
    cout << "No\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string.h>
#include <string>
using namespace std;

class Dice {
private:
  int right, wrong;
  int N, E, W, S;
  int tmp1, tmp2;

public:
  Dice() : right(0), wrong(0), N(0), E(0), W(0), S(0){};
  Dice(int ri, int wr, int n, int e, int w, int s)
      : right(ri), wrong(wr), N(n), E(e), W(w), S(s){};
  void SetDice(int, int, int, int, int, int);
  int ShowRight() { return right; }
  int ShowWrong() { return wrong; }
  int ShowN() { return N; }
  int ShowE() { return E; }
  int ShowW() { return W; }
  int ShowS() { return S; }
  void goN();
  void goE();
  void goW();
  void goS();
};

void Dice::SetDice(int ri, int wr, int n, int e, int w, int s) {
  right = ri;
  wrong = wr;
  N = n;
  S = s;
  W = w;
  E = e;
}
void Dice::goN() {
  tmp1 = N;
  tmp2 = S;
  N = wrong;
  S = right;
  right = tmp1;
  wrong = tmp2;
}
void Dice::goE() {
  tmp1 = E;
  tmp2 = W;
  E = wrong;
  W = right;
  right = tmp1;
  wrong = tmp2;
}
void Dice::goW() {
  tmp1 = W;
  tmp2 = E;
  W = wrong;
  E = right;
  right = tmp1;
  wrong = tmp2;
}
void Dice::goS() {
  tmp1 = S;
  tmp2 = N;
  S = wrong;
  N = right;
  right = tmp1;
  wrong = tmp2;
}

int main() {
  int label1[6];
  int label2[6];
  Dice dice[24];

  int n;
  int a, b;
  int flag = 0;
  int OK_flag = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++)
      cin >> label1[j];
    dice[i].SetDice(label1[0], label1[5], label1[1], label1[3], label1[2],
                    label1[4]);
  }
  for (int p = 0; p < n - 1; p++) {
    for (int q = p + 1; q < n; q++) {

      for (int j = 0; j < 6; j++) {
        for (int i = 0; i < 4; i++) {
          flag = 0;
          if (dice[p].ShowRight() != dice[q].ShowRight())
            flag = 1;
          if (dice[p].ShowWrong() != dice[q].ShowWrong())
            flag = 1;
          if (dice[p].ShowN() != dice[q].ShowN())
            flag = 1;
          if (dice[p].ShowE() != dice[q].ShowE())
            flag = 1;
          if (dice[p].ShowW() != dice[q].ShowW())
            flag = 1;
          if (dice[p].ShowS() != dice[q].ShowS())
            flag = 1;
          if (flag == 0)
            OK_flag = 1;
          dice[q].goS();
          dice[q].goW();
          dice[q].goN();
        }
        if (j == 0 || j == 1)
          dice[q].goN();
        else
          dice[q].goE();
      }
    }
  }
  if (OK_flag == 0)
    cout << "Yes\\n";
  else
    cout << "No\\n";

  return 0;
}