Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define REEP(i, N) for (ll i = N - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a を b の倍数値まで増やす
#define CEIL(c, a, b)                                                          \
  if (a % b == 0) {                                                            \
    c = a / b;                                                                 \
  } else {                                                                     \
    c = a / b + 1;                                                             \
  } // a / b 以上の最小整数
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> red(N, false);
  red[0] = true;
  vector<ll> s(N, 1);
  REP(i, N) {
    ll x, y;
    cin >> x >> y;
    --x;
    --y;
    if (red[x]) {
      if (s[x] <= 1)
        red[x] = false;
      red[y] = true;
      --s[x];
      ++s[y];
    } else {
      --s[x];
      ++s[y];
    }
  }
  ll sum = 0;
  REP(i, N) {
    if (red[i])
      ++sum;
  }
  cout << sum << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define REEP(i, N) for (ll i = N - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a を b の倍数値まで増やす
#define CEIL(c, a, b)                                                          \
  if (a % b == 0) {                                                            \
    c = a / b;                                                                 \
  } else {                                                                     \
    c = a / b + 1;                                                             \
  } // a / b 以上の最小整数
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> red(N, false);
  red[0] = true;
  vector<ll> s(N, 1);
  REP(i, M) {
    ll x, y;
    cin >> x >> y;
    --x;
    --y;
    if (red[x]) {
      if (s[x] <= 1)
        red[x] = false;
      red[y] = true;
      --s[x];
      ++s[y];
    } else {
      --s[x];
      ++s[y];
    }
  }
  ll sum = 0;
  REP(i, N) {
    if (red[i])
      ++sum;
  }
  cout << sum << endl;
}