Problem p02386 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
/*
NumnerOfDice?????????????????????????????§????????????????????????(No)????????????????????°??????(Yes)???????????????CheckConsistentDice_N
?????????????????????????????°???????????§?????????????????????CheckConsistentLabel
?????????????????????????????????????????¢????????????????????????TopFront
*/
class DICE {
private:
  int Label[6];

public:
  DICE();
  void Input();
  void RotateDirection(std::string);
  void Rotate(int, int, int, int);
  int GetLabel(int x) { return Label[x]; }
  void TopFront(int, int);
  bool CheckConsistentLabel(DICE AnotherDice);
};
DICE::DICE() {}
void DICE::Input() {
  for (int i = 0; i < 6; ++i) {
    std::cin >> Label[i];
  }
}
void DICE::RotateDirection(std::string s) {
  if (s == "E") {
    Rotate(0, 3, 5, 2);
  }
  if (s == "N") {
    Rotate(0, 1, 5, 4);
  }
  if (s == "S") {
    Rotate(0, 4, 5, 1);
  }
  if (s == "W") {
    Rotate(0, 2, 5, 3);
  }
}
void DICE::Rotate(int a, int b, int c, int d) {
  std::swap(Label[a], Label[b]);
  std::swap(Label[b], Label[c]);
  std::swap(Label[c], Label[d]);
}
void DICE::TopFront(int top, int front) {
  const int size_str = 7;
  std::string str[size_str] = {"N", "N", "N", "W", "N", "N", "N"};
  for (unsigned int i = 0; i < size_str; ++i) {
    if (front == Label[1]) {
      break;
    }
    RotateDirection(str[i]);
  }

  {
    for (unsigned int i = 0; i < 4; ++i) {
      if (top == Label[0])
        break;
      RotateDirection("W");
    }
  }
}
bool DICE::CheckConsistentLabel(DICE AnotherDice) {
  int NumberLabel[101] = {0};
  for (int i = 0; i < 6; ++i) {
    NumberLabel[Label[i]] += 1;
    NumberLabel[AnotherDice.GetLabel(i)] -= 1;
  }
  int i = 0;
  while (i <= 100) {
    if (NumberLabel[i] != 0) {
      return false;
    }
    ++i;
  }
  return true;
}
bool CheckConsistentDice_N(std::vector<DICE> &dice) {
  const int LastNumberDice = 5;
  for (unsigned int i = 0; i < dice.size(); ++i) {
    for (unsigned int j = i + 1; j < dice.size(); ++j) {
      if (dice[i].CheckConsistentLabel(dice[j])) {
        dice[i].TopFront(dice[j].GetLabel(0), dice[j].GetLabel(1));
        for (int k = 0; k <= LastNumberDice; ++k) {
          if (dice[i].GetLabel(k) != dice[j].GetLabel(k)) {
            break;
          } else {
            if (k == LastNumberDice) {
              return false;
            }
          }
        }
      }
    }
  }
  return true;
}

int main(void) {
  int NumberOfDice;
  std::cin >> NumberOfDice;
  std::vector<DICE> dice(NumberOfDice);
  for (int i = 0; i < dice.size(); i++) {
    dice[i].Input();
  }
  if (CheckConsistentDice_N(dice)) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  // system("pause");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
/*
NumnerOfDice?????????????????????????????§????????????????????????(No)????????????????????°??????(Yes)???????????????CheckConsistentDice_N
?????????????????????????????°???????????§?????????????????????CheckConsistentLabel
?????????????????????????????????????????¢????????????????????????TopFront
*/
class DICE {
private:
  int Label[6];

public:
  DICE();
  void Input();
  void RotateDirection(std::string);
  void Rotate(int, int, int, int);
  int GetLabel(int x) { return Label[x]; }
  void TopFront(int, int);
  bool CheckConsistentLabel(DICE AnotherDice);
};
DICE::DICE() {}
void DICE::Input() {
  for (int i = 0; i < 6; ++i) {
    std::cin >> Label[i];
  }
}
void DICE::RotateDirection(std::string s) {
  if (s == "E") {
    Rotate(0, 3, 5, 2);
  }
  if (s == "N") {
    Rotate(0, 1, 5, 4);
  }
  if (s == "S") {
    Rotate(0, 4, 5, 1);
  }
  if (s == "W") {
    Rotate(0, 2, 5, 3);
  }
}
void DICE::Rotate(int a, int b, int c, int d) {
  std::swap(Label[a], Label[b]);
  std::swap(Label[b], Label[c]);
  std::swap(Label[c], Label[d]);
}
void DICE::TopFront(int top, int front) {
  const int size_str = 7;
  std::string str[size_str] = {"N", "N", "N", "W", "N", "N", "N"};
  for (unsigned int i = 0; i < size_str; ++i) {
    if (front == Label[1]) {
      break;
    }
    RotateDirection(str[i]);
  }
  while (top != Label[0]) {
    RotateDirection("W");
  }
}
bool DICE::CheckConsistentLabel(DICE AnotherDice) {
  int NumberLabel[101] = {0};
  for (int i = 0; i < 6; ++i) {
    NumberLabel[Label[i]] += 1;
    NumberLabel[AnotherDice.GetLabel(i)] -= 1;
  }
  int i = 0;
  while (i <= 100) {
    if (NumberLabel[i] != 0) {
      return false;
    }
    ++i;
  }
  return true;
}
bool CheckConsistentDice_N(std::vector<DICE> &dice) {
  const int LastNumberDice = 5;
  for (unsigned int i = 0; i < dice.size(); ++i) {
    for (unsigned int j = i + 1; j < dice.size(); ++j) {
      if (dice[i].CheckConsistentLabel(dice[j])) {
        dice[i].TopFront(dice[j].GetLabel(0), dice[j].GetLabel(1));
        for (int k = 0; k <= LastNumberDice; ++k) {
          if (dice[i].GetLabel(k) != dice[j].GetLabel(k)) {
            break;
          } else {
            if (k == LastNumberDice) {
              return false;
            }
          }
        }
      }
    }
  }
  return true;
}

int main(void) {
  int NumberOfDice;
  std::cin >> NumberOfDice;
  std::vector<DICE> dice(NumberOfDice);
  for (int i = 0; i < dice.size(); i++) {
    dice[i].Input();
  }
  if (CheckConsistentDice_N(dice)) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  // system("pause");
  return 0;
}