Problem p03691 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, st, ed) for (register int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (register int i = st, i##end = ed; i >= i##end; --i)
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
  return (y < x) ? (x = y, 1) : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
  return (y > x) ? (x = y, 1) : 0;
}
inline int read() {
  int x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    f = -1, c = getchar();
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ '0');
  return x * f;
}
inline ll readll() {
  ll x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    f = -1, c = getchar();
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1ll) + (x << 3ll) + (c ^ '0');
  return x * f;
}
const int maxn = 400 + 10;
struct Edge {
  int x, y;
} E[(int)1e5 + 10];
bitset<maxn> bit[maxn];
bool vis[maxn];
int main() {
#ifndef ONLINE_JUDGE
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
  int n = read(), m = read();
  REP(i, 1, m) E[i].x = read(), E[i].y = read();
  REP(i, 1, n) {
    bit[i][i] = 1;
    DREP(j, m, 1) {
      int x = E[j].x, y = E[j].y;
      if (bit[i][x] && bit[i][y]) {
        vis[i] = 1;
        break;
      }
      if (bit[i][x] || bit[i][y])
        bit[i][x] = bit[i][y] = 1;
    }
  }
  int ans = 0;
  REP(i, 1, n)
  if (!vis[i])
      REP(j, i + 1, n) if (!vis[j]) if ((bit[i] & bit[j]).count() == 0)++ ans;
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, st, ed) for (register int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (register int i = st, i##end = ed; i >= i##end; --i)
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
  return (y < x) ? (x = y, 1) : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
  return (y > x) ? (x = y, 1) : 0;
}
inline int read() {
  int x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    f = -1, c = getchar();
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ '0');
  return x * f;
}
inline ll readll() {
  ll x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    f = -1, c = getchar();
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1ll) + (x << 3ll) + (c ^ '0');
  return x * f;
}
const int maxn = 400 + 10;
struct Edge {
  int x, y;
} E[(int)1e5 + 10];
bitset<maxn> bit[maxn];
bool vis[maxn];
int main() {
  int n = read(), m = read();
  REP(i, 1, m) E[i].x = read(), E[i].y = read();
  REP(i, 1, n) {
    bit[i][i] = 1;
    DREP(j, m, 1) {
      int x = E[j].x, y = E[j].y;
      if (bit[i][x] && bit[i][y]) {
        vis[i] = 1;
        break;
      }
      if (bit[i][x] || bit[i][y])
        bit[i][x] = bit[i][y] = 1;
    }
  }
  int ans = 0;
  REP(i, 1, n)
  if (!vis[i])
      REP(j, i + 1, n) if (!vis[j]) if ((bit[i] & bit[j]).count() == 0)++ ans;
  printf("%d\n", ans);
  return 0;
}