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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
const int one = 1;
const int big = (one << 20);
typedef long long int llint;
const int Llong = 0;
const int Rlong = 1;
const int Lbow = 2;
const int Rbow = 3;
vector<tuple<llint, llint, llint, llint>>
    bow; //??????????????????????£????????£?
inline llint GCDme(llint n, llint m) {
  if (n < m) {
    swap(n, m);
  }
  if (n == 0 || m == 0) {
    return n + m;
  }
  return GCDme(m, n % m);
}
inline llint LCMme(llint n, llint m) { return (n * m) / GCDme(n, m); }
llint make_bow(llint ter) {
  llint Llcm, Rlcm, Smom; //??????????°????????????????????????¢????????????
  if (get<Lbow>(bow[ter]) == 0) {
    Llcm = 1;
  } else {
    Llcm = make_bow(get<Lbow>(bow[ter]));
  }
  if (get<Rbow>(bow[ter]) == 0) {
    Rlcm = 1;
  } else {
    Rlcm = make_bow(get<Rbow>(bow[ter]));
  }
  Smom = LCMme(Llcm * get<Llong>(bow[ter]), Rlcm * get<Rlong>(bow[ter]));
  return (Smom / get<Llong>(bow[ter])) + (Smom / get<Rlong>(bow[ter]));
}
bool solve(void) {
  llint i, n, a, b, c, d, e, ans;
  bow.clear(); //?£????????????????
  llint used_bow[101] = {0};
  llint top_bow = 0;
  scanf("%lld", &n);
  if (n == 0) {
    return false;
  }
  bow.push_back(make_tuple(1, 1, 0, 0)); // 1???????£?????§??????????
  for (i = 1; i <= n; i++) {
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    bow.push_back(make_tuple(a, b, c, d));
    used_bow[c] = 1;
    used_bow[d] = 1;
  }
  for (i = 1; i <= n; i++) {
    if (used_bow[i] == 0) {
      top_bow = i;
      break;
    }
  }
  ans = make_bow(top_bow);
  printf("%lld\\n", ans);
  return true;
}
int main(void) {
  while (solve()) {
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
const int one = 1;
const int big = (one << 20);
typedef long long int llint;
const int Llong = 0;
const int Rlong = 1;
const int Lbow = 2;
const int Rbow = 3;
vector<tuple<int, int, int, int>> bow; //??????????????????????£????????£?
inline int GCDme(int n, int m) {
  if (n < m) {
    swap(n, m);
  }
  if (n == 0 || m == 0) {
    return n + m;
  }
  return GCDme(m, n % m);
}
inline int LCMme(int n, int m) { return (n * m) / GCDme(n, m); }
int make_bow(int ter) {
  int Llcm, Rlcm, Smom; //??????????°????????????????????????¢????????????
  if (get<Lbow>(bow[ter]) == 0) {
    Llcm = 1;
  } else {
    Llcm = make_bow(get<Lbow>(bow[ter]));
  }
  if (get<Rbow>(bow[ter]) == 0) {
    Rlcm = 1;
  } else {
    Rlcm = make_bow(get<Rbow>(bow[ter]));
  }
  Smom = LCMme(Llcm * get<Llong>(bow[ter]), Rlcm * get<Rlong>(bow[ter]));
  return (Smom / get<Llong>(bow[ter])) + (Smom / get<Rlong>(bow[ter]));
}
bool solve(void) {
  int i, n, a, b, c, d, e, ans;
  bow.clear(); //?£????????????????
  int used_bow[101] = {0};
  int top_bow = 0;
  scanf("%d", &n);
  if (n == 0) {
    return false;
  }
  bow.push_back(make_tuple(1, 1, 0, 0)); // 1???????£?????§??????????
  for (i = 1; i <= n; i++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    bow.push_back(make_tuple(a, b, c, d));
    used_bow[c] = 1;
    used_bow[d] = 1;
  }
  for (i = 1; i <= n; i++) {
    if (used_bow[i] == 0) {
      top_bow = i;
      break;
    }
  }
  ans = make_bow(top_bow);
  printf("%d\\n", ans);
  return true;
}
int main(void) {
  while (solve()) {
  }
  return 0;
}