Problem p03691 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a, b, c) for (register int a = (b), a##end = (c); a <= a##end; ++a)
#define DEP(a, b, c) for (register int a = (b), a##end = (c); a >= a##end; --a)
const int MAXN = 400 + 10, MAXM = 50000 + 10;
int n, m, ans, imp[MAXN];
std::bitset<MAXN> f[MAXN];
struct node {
  int u, v;
};
node side[MAXM];
template <typename T> inline void read(T &x) {
  T data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = ((T)data << 3) + ((T)data << 1) + (ch ^ '0'), ch = getchar();
  x = data * w;
}
template <typename T> inline void write(T x, char ch = '\0') {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  if (ch != '\0')
    putchar(ch);
}
template <typename T> inline void chkmin(T &x, T y) { x = (y < x ? y : x); }
template <typename T> inline void chkmax(T &x, T y) { x = (y > x ? y : x); }
template <typename T> inline T min(T x, T y) { return x < y ? x : y; }
template <typename T> inline T max(T x, T y) { return x > y ? x : y; }
inline void init() {
  REP(i, 1, n) {
    f[i][i] = true;
    DEP(j, m, 1) {
      if (f[i][side[j].u] && f[i][side[j].v]) {
        imp[i] = 1;
        break;
      }
      if (f[i][side[j].u] || f[i][side[j].v])
        f[i][side[j].u] = f[i][side[j].v] = true;
    }
  }
}
int main() {
  read(n);
  read(m);
  REP(i, 1, m) {
    int u, v;
    read(u);
    read(v);
    side[i] = (node){u, v};
  }
  init();
  REP(i, 1, n)
  if (!imp[i]) REP(j, i + 1, n) if (!imp[j]) if ((f[i] & f[j]).any() == 0)
      ans++;
  write(ans, '\n');
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a, b, c) for (register int a = (b), a##end = (c); a <= a##end; ++a)
#define DEP(a, b, c) for (register int a = (b), a##end = (c); a >= a##end; --a)
const int MAXN = 400 + 10, MAXM = 100000 + 10;
int n, m, ans, imp[MAXN];
std::bitset<MAXN> f[MAXN];
struct node {
  int u, v;
};
node side[MAXM];
template <typename T> inline void read(T &x) {
  T data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = ((T)data << 3) + ((T)data << 1) + (ch ^ '0'), ch = getchar();
  x = data * w;
}
template <typename T> inline void write(T x, char ch = '\0') {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  if (ch != '\0')
    putchar(ch);
}
template <typename T> inline void chkmin(T &x, T y) { x = (y < x ? y : x); }
template <typename T> inline void chkmax(T &x, T y) { x = (y > x ? y : x); }
template <typename T> inline T min(T x, T y) { return x < y ? x : y; }
template <typename T> inline T max(T x, T y) { return x > y ? x : y; }
inline void init() {
  REP(i, 1, n) {
    f[i][i] = true;
    DEP(j, m, 1) {
      if (f[i][side[j].u] && f[i][side[j].v]) {
        imp[i] = 1;
        break;
      }
      if (f[i][side[j].u] || f[i][side[j].v])
        f[i][side[j].u] = f[i][side[j].v] = true;
    }
  }
}
int main() {
  read(n);
  read(m);
  REP(i, 1, m) {
    int u, v;
    read(u);
    read(v);
    side[i] = (node){u, v};
  }
  init();
  REP(i, 1, n)
  if (!imp[i]) REP(j, i + 1, n) if (!imp[j]) if ((f[i] & f[j]).any() == 0)
      ans++;
  write(ans, '\n');
  return 0;
}