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

#include <cassert>
#include <iostream>
#include <string>
#include <vector>

struct Meirei {
  std::string mei;
  std::string str;
};

struct Node {
  Node() {
    umu = false;
    a = NULL;
    c = NULL;
    g = NULL;
    t = NULL;
  }
  bool umu;
  Node *a;
  Node *c;
  Node *g;
  Node *t;
};

class Tree {
public:
  Tree() { m_root = new Node(); }
  void insert(std::string moji);
  bool find(std::string moji);

private:
  Node *m_root;
};

void Tree::insert(std::string moji) {
  Node *node = m_root;
  for (int i = 0; i < moji.size(); i++) {
    if (moji[i] == 'A') {
      if (node->a == NULL) {
        node->a = new Node();
      }
      node = node->a;
    } else if (moji[i] == 'C') {
      if (node->c == NULL) {
        node->c = new Node();
      }
      node = node->c;
    } else if (moji[i] == 'G') {
      if (node->g == NULL) {
        node->g = new Node();
      }
      node = node->g;
    } else if (moji[i] == 'T') {
      if (node->t == NULL) {
        node->t = new Node();
      }
      node = node->t;
    } else {
      assert(true);
    }
  }
  node->umu = true;
}

bool Tree::find(std::string moji) {
  Node *node = m_root;
  for (int i = 0; i < moji.size(); i++) {
    if (moji[i] == 'A') {
      if (node->a == NULL) {
        return false;
      }
      node = node->a;
    } else if (moji[i] == 'C') {
      if (node->c == NULL) {
        return false;
      }
      node = node->c;
    } else if (moji[i] == 'G') {
      if (node->g == NULL) {
        return false;
      }
      node = node->g;
    } else if (moji[i] == 'T') {
      if (node->t == NULL) {
        return false;
      }
      node = node->t;
    } else {
      assert(true);
    }
  }
  if (node->umu) {
    return true;
  }
  return false;
}

// typedef std::vector<MEIREI> VecMeirei;
// typedef std::vector<std::string> WORDS;
// typedef std::vector<bool> ARINASHI;
// void input();
// bool find(WORDS jisho, std::string str);
void output(bool result);
//-------------------------------------------------------------------
int main() {
  Tree tree = Tree();

  long n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::string meirei;
    std::cin >> meirei;
    std::string moji;
    std::cin >> moji;
    if (meirei == "insert") {
      tree.insert(moji);
    } else if (meirei == "find") {
      output(tree.find(moji));
    }
  }
  return 0;
}
//-------------------------------------------------------------------
void output(bool result) {
  if (result) {
    std::cout << "yes" << std::endl;
  } else {
    std::cout << "no" << std::endl;
  }
  return;
}
//-------------------------------------------------------------------

Error: TLE

Fixed submission:

#include <cassert>
#include <iostream>
#include <string>
#include <vector>

struct MEIREI {
  std::string mei;
  std::string str;
};
//
typedef std::vector<MEIREI> VecMeirei;
//
typedef std::vector<std::string> WORDS;

//
void input();
bool find(WORDS jisho, std::string str);
void output(bool result);
//-------------------------------------------------------------------
int main() {
  input();
  return 0;
}
//-------------------------------------------------------------------
void input() {
  //
  long n;
  std::cin >> n;
  VecMeirei Meirei;
  Meirei.resize(n);

  //
  WORDS JishoA;
  WORDS JishoG;
  WORDS JishoC;
  WORDS JishoT;

  for (int i = 0; i < n; i++) {
    std::cin >> Meirei[i].mei;
    // log       std::cout <<  "Meirei[i].mei::" << Meirei[i].mei << std::endl;
    if (Meirei[i].mei == "insert") {
      std::cin >> Meirei[i].str;
      if (Meirei[i].str[0] == 'A') {
        JishoA.push_back(Meirei[i].str);
      } else if (Meirei[i].str[0] == 'C') {
        JishoC.push_back(Meirei[i].str);
      } else if (Meirei[i].str[0] == 'T') {
        JishoT.push_back(Meirei[i].str);
      } else if (Meirei[i].str[0] == 'G') {
        JishoG.push_back(Meirei[i].str);
      } else {
        assert(true);
      }
    } else if (Meirei[i].mei == "find") {
      std::cin >> Meirei[i].str;
      bool ret = false;
      if (Meirei[i].str[0] == 'A') {
        ret = find(JishoA, Meirei[i].str);
      } else if (Meirei[i].str[0] == 'C') {
        ret = find(JishoC, Meirei[i].str);
      } else if (Meirei[i].str[0] == 'T') {
        ret = find(JishoT, Meirei[i].str);
      } else if (Meirei[i].str[0] == 'G') {
        ret = find(JishoG, Meirei[i].str);
      } else {
        assert(true);
      }
      output(ret);
    } else {
      // log           std::cout << "input err" << std::endl;
      break;
    }
    // log       std::cout <<  "Meirei[i].str::" << Meirei[i].str << std::endl;
  }
  return;
}
//-------------------------------------------------------------------
bool find(WORDS jisho, std::string str) {
  for (int i = 0; i < jisho.size(); i++) {
    if (jisho[i] == str) {
      return true;
    }
  }
  return false;
}
//-------------------------------------------------------------------
void output(bool result) {
  if (result) {
    std::cout << "yes" << std::endl;
  } else {
    std::cout << "no" << std::endl;
  }
  return;
}
//-------------------------------------------------------------------