Problem p03691 (C++)

Buggy submission (status: Runtime Error):
/************************************************
 * Au: Hany01
 * Prob: c
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
 ************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++i)
#define For(i, j, k)                                                           \
  for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++i)
#define Fordown(i, j, k)                                                       \
  for (register int i = (j), i##_end_ = (k); i >= i##_end_; --i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}

inline int read() {
  static int _, __;
  static char c_;
  for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar())
    if (c_ == '-')
      __ = -1;
  for (; c_ >= '0' && c_ <= '9'; c_ = getchar())
    _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
  return _ * __;
}
// EOT

const int maxn = 405, maxm = 5e4 + 5;

int n, m, cnt;
bitset<maxn> f[maxn], fuck;
PII E[maxm];

inline void check(int x) {
  f[x][x] = 1;
  Fordown(i, m, 1) {
    if (f[x][E[i].X] && f[x][E[i].Y]) {
      fuck[x] = 1;
      return;
    }
    if (f[x][E[i].X] || f[x][E[i].Y])
      f[x][E[i].X] = f[x][E[i].Y] = 1;
  }
}

int main() {
#ifdef hany01
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif

  n = read(), m = read();
  For(i, 1, m) E[i].X = read(), E[i].Y = read();
  For(i, 1, n) check(i);

  For(i, 1, n) if (!fuck[i])
      For(j, i + 1, n) if (!fuck[j]) if (!(f[i] & f[j]).any())++ cnt;
  printf("%d\n", cnt);

  return 0;
}

Fixed submission:
/************************************************
 * Au: Hany01
 * Prob: c
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
 ************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++i)
#define For(i, j, k)                                                           \
  for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++i)
#define Fordown(i, j, k)                                                       \
  for (register int i = (j), i##_end_ = (k); i >= i##_end_; --i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}

inline int read() {
  static int _, __;
  static char c_;
  for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar())
    if (c_ == '-')
      __ = -1;
  for (; c_ >= '0' && c_ <= '9'; c_ = getchar())
    _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
  return _ * __;
}
// EOT

const int maxn = 405, maxm = 1e5 + 5;

int n, m, cnt;
bitset<maxn> f[maxn], fuck;
PII E[maxm];

inline void check(int x) {
  f[x][x] = 1;
  Fordown(i, m, 1) {
    if (f[x][E[i].X] && f[x][E[i].Y]) {
      fuck[x] = 1;
      return;
    }
    if (f[x][E[i].X] || f[x][E[i].Y])
      f[x][E[i].X] = f[x][E[i].Y] = 1;
  }
}

int main() {
#ifdef hany01
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif

  n = read(), m = read();
  For(i, 1, m) E[i].X = read(), E[i].Y = read();
  For(i, 1, n) check(i);

  For(i, 1, n) if (!fuck[i])
      For(j, i + 1, n) if (!fuck[j]) if (!(f[i] & f[j]).any())++ cnt;
  printf("%d\n", cnt);

  return 0;
}