Problem p00431 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int c
    [101]
    [101]; /*???i????????????????????\\?????????c[i][j]???;j=0??????i????????????????????°*/

int chain(int e, int l, int done[]) {
  int i, j;
  int lmax = l, ltemp;
  if (c[e][0]) {
    for (j = 1; j <= c[e][0]; j++) {
      if (done[c[e][j]]) {
        done[c[e][j]] = 0;
        ltemp = chain(c[e][j], l + 1, done);
        done[c[e][j]] = 1;
        if (ltemp > lmax)
          lmax = ltemp;
      }
    }
    return lmax;
  } else {
    return l;
  }
}
int main() {
  int n, ans, temp;
  int done[101]; /*i???????????¨??? c[i]=1,i=0??????i???max???*/
  int a, b;
  int i, j;
  scanf("%d", &n);
  while (n) {
    /*?????????*/
    for (i = 0; i <= 100; i++) {
      done[i] = 0;
      for (j = 0; j <= 100; j++) {
        c[i][j] = 0;
      }
    }
    /*?????????????????????*/
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      done[a] = done[b] = 1;
      c[a][0]++;
      c[b][0]++;
      c[a][c[a][0]] = b;
      c[b][c[b][0]] = a;
      if (done[0] < a)
        done[0] = a;
      if (done[0] < b)
        done[0] = b;
    }
    /*?¢??????¨*/
    /*printf("lim: %d\\n",done[0]);
    for(i=1;i<=done[0];i++){
        if(c[i][0]){
            printf("%d is connected with ",i);
            for(j=1;j<=c[i][0];j++)printf("%d,",c[i][j]);
            printf("\\n");
        }
    }*/
    ans = 0;
    /*?§????????±???????????????????????±???????*/
    for (i = 1; i <= 100; i++) {
      if (done[i]) {
        done[i] = 0;
        temp = chain(i, 1, done);
        done[i] = 1;
        if (ans < temp)
          ans = temp;
      }
    }
    printf("%d\\n", ans);
    scanf("%d", &n);
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
int c
    [101]
    [101]; /*???i????????????????????\\?????????c[i][j]???;j=0??????i????????????????????°*/

int chain(int e, int l, int done[]) {
  int cpy[101];
  int i, j;
  int lmax = l, ltemp;
  for (i = 0; i <= done[0]; i++)
    cpy[i] = done[i]; /*?????????????????????????????£??????*/
  if (c[e][0]) {
    for (j = 1; j <= c[e][0]; j++) {
      if (cpy[c[e][j]]) {
        cpy[c[e][j]] = 0;
        ltemp = chain(c[e][j], l + 1, cpy);
        cpy[c[e][j]] = 1;
        if (ltemp > lmax)
          lmax = ltemp;
      }
    }
    return lmax;
  } else {
    return l;
  }
}
int main() {
  int n, ans, temp;
  int done[101]; /*i???????????¨??? c[i]=1,i=0??????i???max???*/
  int a, b;
  int i, j;
  scanf("%d", &n);
  while (n) {
    /*?????????*/
    for (i = 0; i <= 100; i++) {
      done[i] = 0;
      for (j = 0; j <= 100; j++) {
        c[i][j] = 0;
      }
    }
    /*?????????????????????*/
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      done[a] = done[b] = 1;
      c[a][0]++;
      c[b][0]++;
      c[a][c[a][0]] = b;
      c[b][c[b][0]] = a;
      if (done[0] < a)
        done[0] = a;
      if (done[0] < b)
        done[0] = b;
    }
    /*?¢??????¨*/
    /*printf("lim: %d\\n",done[0]);
    for(i=1;i<=done[0];i++){
        if(c[i][0]){
            printf("%d is connected with ",i);
            for(j=1;j<=c[i][0];j++)printf("%d,",c[i][j]);
            printf("\\n");
        }
    }*/
    ans = 0;
    /*?§????????±???????????????????????±???????*/
    for (i = 1; i <= 100; i++) {
      if (done[i]) {
        done[i] = 0;
        temp = chain(i, 1, done);
        done[i] = 1;
        if (ans < temp)
          ans = temp;
      }
    }
    printf("%d\\n", ans);
    scanf("%d", &n);
  }
}