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

#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N;
int *marked_boss;

struct Node {
  bool isMarked;
  int marked_time;
};

struct Query {
  Query(int arg_query_time, int arg_value) {
    query_time = arg_query_time;
    value = arg_value;
  }
  int query_time, value;
};

Node *info;

int get_marked_boss(int id, int query_time) {

  if (info[id].isMarked == true && info[id].marked_time < query_time) {
    return id;
  } else {
    return marked_boss[id] = get_marked_boss(marked_boss[id], query_time);
  }
}

int main() {

  int Q, value, tmp;
  char buf[2];
  ll ans;

  marked_boss = new int[100001];
  info = (Node *)malloc(sizeof(Node) * (100001));

  stack<Query> S;

  while (true) {
    scanf("%d %d", &N, &Q);
    if (N == 0 && Q == 0)
      break;

    for (int i = 1; i <= N; i++) {
      info[i].isMarked = false;
      info[i].marked_time = BIG_NUM;
    }

    marked_boss[1] = 1;
    info[1].isMarked = true;
    info[1].marked_time = 0;

    for (int i = 2; i <= N; i++) {
      scanf("%d", &value);
      marked_boss[i] = value;
    }

    for (int time = 1; time <= Q; time++) {

      scanf("%s %d", buf, &value);

      if (buf[0] == 'Q') {
        S.push(Query(time, value));
      } else {
        info[value].isMarked = true;
        info[value].marked_time = min(info[value].marked_time, time);
      }
    }

    ans = 0;

    while (!S.empty()) {
      tmp = get_marked_boss(S.top().value, S.top().query_time);
      ans += tmp;
      S.pop();
    }

    printf("%lld\\n", ans);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N;
int *marked_boss;

struct Node {
  bool isMarked;
  int marked_time; //????????????????????????
};

struct Query {
  Query(int arg_query_time, int arg_value) {
    query_time = arg_query_time;
    value = arg_value;
  }
  int query_time, value;
};

Node *info;

//???????????????????????????????±????????????????????????§?????????
int get_marked_boss(int id, int query_time) {
  if (info[id].isMarked == true &&
      info[id].marked_time <
          query_time) { //?????¨??????????????????????????????????????????????????????????????£?????´???
    return id;
  } else {
    return marked_boss[id] = get_marked_boss(marked_boss[id], query_time);
  }
}

int main() {

  int Q, value;
  char buf[2];
  ll ans;

  marked_boss = new int[100001];
  info = (Node *)malloc(sizeof(Node) * (100001));

  stack<Query> S;

  while (true) {
    scanf("%d %d", &N, &Q);
    if (N == 0 && Q == 0)
      break;

    for (int i = 1; i <= N; i++) {
      info[i].isMarked = false;
    }

    marked_boss[1] = 1;
    info[1].isMarked = true;
    info[1].marked_time = 0;

    for (int i = 2; i <= N; i++) {
      scanf("%d", &value);
      marked_boss[i] = value;
    }

    for (int time = 1; time <= Q; time++) {

      scanf("%s %d", buf, &value);

      if (buf[0] == 'Q') {
        S.push(Query(time, value));
      } else {
        info[value].isMarked = true;
        info[value].marked_time = time;
      }
    }

    ans = 0;

    while (!S.empty()) {
      ans += get_marked_boss(S.top().value, S.top().query_time);
      S.pop();
    }

    printf("%lld\\n", ans);
  }

  return 0;
}