Problem p03575 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define STR(i, str) for (int i = 0; (str)[i]; i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX3(a, b, c)                                                          \
  ((a) > (b) ? (a) > (c) ? (a) : (c) : (b) > (c) ? (b) : (c))
#define MIN3(a, b, c)                                                          \
  ((a) < (b) ? (a) < (c) ? (a) : (c) : (b) < (c) ? (b) : (c))
#define RNG(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))
#define RNG3(a, b, c)                                                          \
  ((a) > (b)   ? (b) > (c)   ? (a) - (c)                                       \
                 : (c) > (a) ? (c) - (b)                                       \
                             : (a) - (b)                                       \
     : (b) > (c) ? (c) > (a) ? (b) - (a) : (b) - (c)                           \
                 : (c) - (a))
#define MAXS(a, b)                                                             \
  {                                                                            \
    if ((a) < (b))                                                             \
      (a) = (b);                                                               \
  }
#define MINS(a, b)                                                             \
  {                                                                            \
    if ((a) > (b))                                                             \
      (a) = (b);                                                               \
  }

int main() {
  int n, m, a[55], b[55], uni[55], ans = 0;
  scanf("%d%d", &n, &m);
  REP(i, m) {
    scanf("%d%d", a + i, b + i);
    a[i]--;
    b[i]--;
  }
  REP(i, m) {
    REP(j, n) uni[j] = j;
    REP(j, m) if (i != j) {
      while (uni[b[j]] != uni[uni[b[j]]])
        uni[b[j]] = uni[uni[b[j]]];
      uni[uni[b[j]]] = uni[a[j]];
    }
    while (uni[a[i]] != uni[uni[a[i]]])
      uni[a[i]] = uni[uni[a[i]]];
    while (uni[b[i]] != uni[uni[b[i]]])
      uni[b[i]] = uni[uni[b[i]]];
    if (uni[a[i]] != uni[b[i]])
      ans++;
  }
  printf("%d\n", ans);
}

Fixed submission:
#include <stdio.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define STR(i, str) for (int i = 0; (str)[i]; i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX3(a, b, c)                                                          \
  ((a) > (b) ? (a) > (c) ? (a) : (c) : (b) > (c) ? (b) : (c))
#define MIN3(a, b, c)                                                          \
  ((a) < (b) ? (a) < (c) ? (a) : (c) : (b) < (c) ? (b) : (c))
#define RNG(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))
#define RNG3(a, b, c)                                                          \
  ((a) > (b)   ? (b) > (c)   ? (a) - (c)                                       \
                 : (c) > (a) ? (c) - (b)                                       \
                             : (a) - (b)                                       \
     : (b) > (c) ? (c) > (a) ? (b) - (a) : (b) - (c)                           \
                 : (c) - (a))
#define MAXS(a, b)                                                             \
  {                                                                            \
    if ((a) < (b))                                                             \
      (a) = (b);                                                               \
  }
#define MINS(a, b)                                                             \
  {                                                                            \
    if ((a) > (b))                                                             \
      (a) = (b);                                                               \
  }

int main() {
  int n, m, a[55], b[55], uni[55], ans = 0;
  scanf("%d%d", &n, &m);
  REP(i, m) {
    scanf("%d%d", a + i, b + i);
    a[i]--;
    b[i]--;
  }
  REP(i, m) {
    REP(j, n) uni[j] = j;
    REP(j, m) if (i != j) {
      while (uni[a[j]] != uni[uni[a[j]]])
        uni[a[j]] = uni[uni[a[j]]];
      while (uni[b[j]] != uni[uni[b[j]]])
        uni[b[j]] = uni[uni[b[j]]];
      uni[uni[b[j]]] = uni[a[j]];
    }
    while (uni[a[i]] != uni[uni[a[i]]])
      uni[a[i]] = uni[uni[a[i]]];
    while (uni[b[i]] != uni[uni[b[i]]])
      uni[b[i]] = uni[uni[b[i]]];
    if (uni[a[i]] != uni[b[i]])
      ans++;
  }
  printf("%d\n", ans);
}