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

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

typedef struct {
  int height;
  int targetMaxHeight;
} Info;

#define ARRAYMAX 100010
Info InfoArray[ARRAYMAX];

#define DEBUG

int main() {
  int i, j, k, m;

  // printf("size_t:%ld\\n", sizeof(size_t));

  for (i = 0; i < ARRAYMAX; i++) {
    InfoArray[i].height = 0;
    InfoArray[i].targetMaxHeight = 0;
  }
#if 1
  char str[1000];
  fgets(str, sizeof(str), stdin);

  char *temp;
  temp = strtok(str, " \\n");
  // 展望台の数
  int TenbodaiNum = atoi(temp);

  // 道の数
  temp = strtok(NULL, " \\n");
  int PathNum = atoi(temp);
#else
  int TenbodaiNum, PathNum;
  cin >> TenbodaiNum >> PathNum;
#endif

  // 高さの取得
#if 0
    fgets(str, sizeof(str), stdin);

    int hoge = 0;
    temp = strtok(str, " \\n");

    while (temp != NULL)
    {
        //if (hoge >= ARRAYMAX) break;
        InfoArray[hoge].height = atoi(temp);
        hoge++;
        temp = strtok(NULL, " \\n");
    }
#else

  for (i = 0; i < TenbodaiNum; i++) {
    cin >> InfoArray[i].height;
  }
#endif

  // 道情報取得
  for (i = 0; i < PathNum; i++) {
    int iPos1;
    int iPos2;
#if 0
        fgets(str, sizeof(str), stdin);
        temp = strtok(str, " \\n");
        iPos1 = atoi(temp) -1;
        temp = strtok(NULL, " \\n");
        iPos2 = atoi(temp) -1;
#endif
    cin >> iPos1 >> iPos2;
    iPos1--;
    iPos2--;

    // if (iPos1 >= ARRAYMAX) continue;
    // if (iPos2 >= ARRAYMAX) continue;

    if (iPos1 == iPos2)
      continue;

    if (InfoArray[iPos1].targetMaxHeight < InfoArray[iPos2].height) {
      InfoArray[iPos1].targetMaxHeight = InfoArray[iPos2].height;
    }
    if (InfoArray[iPos2].targetMaxHeight < InfoArray[iPos1].height) {
      InfoArray[iPos2].targetMaxHeight = InfoArray[iPos1].height;
    }
  }

  // 判定

  int iGoodNum = 0;

  for (i = 0; i < TenbodaiNum; i++) {
    // if (i >= ARRAYMAX) continue;
    if (InfoArray[i].height > InfoArray[i].targetMaxHeight)
      iGoodNum++;
  }

  printf("%d\\n", iGoodNum);

  return 0;
}


Error: 0

Fixed submission:

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

typedef struct {
  int height;
  int targetMaxHeight;
} Info;

#define ARRAYMAX 100010
Info InfoArray[ARRAYMAX];

#define DEBUG

int main() {
  int i, j, k, m;

  // printf("size_t:%ld\\n", sizeof(size_t));

  for (i = 0; i < ARRAYMAX; i++) {
    InfoArray[i].height = 0;
    InfoArray[i].targetMaxHeight = 0;
  }
#if 1
  char str[1000];
  fgets(str, sizeof(str), stdin);

  char *temp;
  temp = strtok(str, " \\n");
  // 展望台の数
  int TenbodaiNum = atoi(temp);

  // 道の数
  temp = strtok(NULL, " \\n");
  int PathNum = atoi(temp);

  // 高さの取得

  fgets(str, sizeof(str), stdin);

  int hoge = 0;
  temp = strtok(str, " \\n");

  while (temp != NULL) {
    // if (hoge >= ARRAYMAX) break;
    InfoArray[hoge].height = atoi(temp);
    hoge++;
    temp = strtok(NULL, " \\n");
  }
#else
  int TenbodaiNum, PathNum;
  cin >> TenbodaiNum >> PathNum;

  for (i = 0; i < TenbodaiNum; i++) {
    cin >> InfoArray[i].height;
  }
#endif

  // 道情報取得
  for (i = 0; i < PathNum; i++) {
    int iPos1;
    int iPos2;
#if 0
        fgets(str, sizeof(str), stdin);
        temp = strtok(str, " \\n");
        iPos1 = atoi(temp) -1;
        temp = strtok(NULL, " \\n");
        iPos2 = atoi(temp) -1;
#endif
    cin >> iPos1 >> iPos2;
    iPos1--;
    iPos2--;

    // if (iPos1 >= ARRAYMAX) continue;
    // if (iPos2 >= ARRAYMAX) continue;

    if (iPos1 == iPos2)
      continue;

    if (InfoArray[iPos1].targetMaxHeight < InfoArray[iPos2].height) {
      InfoArray[iPos1].targetMaxHeight = InfoArray[iPos2].height;
    }
    if (InfoArray[iPos2].targetMaxHeight < InfoArray[iPos1].height) {
      InfoArray[iPos2].targetMaxHeight = InfoArray[iPos1].height;
    }
  }

  // 判定

  int iGoodNum = 0;

  for (i = 0; i < TenbodaiNum; i++) {
    // if (i >= ARRAYMAX) continue;
    if (InfoArray[i].height > InfoArray[i].targetMaxHeight)
      iGoodNum++;
  }

  printf("%d\\n", iGoodNum);

  return 0;
}