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

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

signed main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int t[100010], s[100010], d[100010];
    int s2[100010], d2[100010];
    memset(s2, -1, sizeof(s2));
    memset(d2, -1, sizeof(d2));
    map<int, int> mp;
    rep(i, 0, m) {
      cin >> t[i] >> s[i] >> d[i];
      mp[t[i]];
    }

    int num = 0;
    for (auto &x : mp)
      x.sc = num++;
    rep(i, 0, m) {
      // printf("t[%lld] = %lld, mp[t[i]] = %lld\\n", i, t[i], mp[t[i]]);
      s2[mp[t[i]]] = s[i];
      d2[mp[t[i]]] = d[i];
    }

    bool infect[100010] = {};
    infect[1] = true;
    rep(i, 0, 100010) {
      if (s2[i] == -1)
        continue;
      if (infect[s2[i]]) {
        infect[d2[i]] = true;
      }
    }
    int ans = 0;
    rep(i, 0, 100000) {
      if (infect[i])
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

signed main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int t, s[100010], d[100010];
    memset(s, -1, sizeof(s));
    memset(d, -1, sizeof(d));
    rep(i, 0, m) {
      cin >> t;
      cin >> s[t] >> d[t];
    }

    bool infect[100010] = {};
    infect[1] = true;
    rep(i, 0, 100010) {
      if (s[i] == -1)
        continue;
      if (infect[s[i]]) {
        infect[d[i]] = true;
      }
    }
    int ans = 0;
    rep(i, 0, 100010) {
      if (infect[i])
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}