Buggy python submission (verdict: Time Limit Exceeded):
def f1(l1):
    ret = []
    for i in l1:
      for n,j in enumerate(li[i]):
        if j:
            if n in used or n in l1:
                return False
            elif n not in tree[nest-1] and n not in ret:
                ret.append(n)
    return ret


N = int(input())
li = []
for _ in range(N):
    li.append(list(map(int,list(input()))))
    
max_nest = 0
for i in range(N):
    tree = [[]]
    used = []
    tree.append([i])
    nest = 1
    while True:
        ret = f1(tree[nest])
        nest += 1
        if ret == False:
            break
        elif ret != []:
            tree.append(ret)
            used.extend(tree[nest-2])
        else:
            if max_nest < nest:
                max_nest = nest
            break
        
print(max_nest-1)

Fixed submission:
def f1(l1):
    ret = []
    for i in l1:
      for n,j in enumerate(li[i]):
        if j:
            if n in used or n in l1:
                return False
            elif n not in tree[nest-1] and n not in ret:
                ret.append(n)
    return ret


N = int(input())
li = []
for _ in range(N):
    li.append(list(map(int,list(input()))))
    
max_nest = 0
for i in range(N):
    tree = [[]]
    used = []
    tree.append([i])
    nest = 1
    while True:
        ret = f1(tree[nest])
        nest += 1
        if ret == False:
            break
        elif ret != []:
            tree.append(ret)
            used.extend(tree[nest-2])
        else:
            if max_nest < nest:
                max_nest = nest
            break
        
print(max_nest-1)

Buggy python submission (verdict: Time Limit Exceeded):
def f1(l1):
    ret = []
    for i in l1:
      for n,j in enumerate(li[i]):
        if j == 1:
            if n in used or n in l1:
                return False
            elif n not in tree[nest-1]:
                ret.append(n)
    return list(set(ret))


N = int(input())
li = []
for _ in range(N):
    li.append(list(map(int,list(input()))))
    
max_nest = 0
for i in range(N):
    tree = [[]]
    used = []
    tree.append([i])
    nest = 1
    while True:
        ret = f1(tree[nest])
        nest += 1
        if ret == False:
            break
        elif ret != []:
            tree.append(ret)
            used.extend(tree[nest-2])
        else:
            if max_nest < nest:
                max_nest = nest
            break
        
print(max_nest-1)

Fixed submission:
def f1(l1):
    ret = []
    for i in l1:
      for n,j in enumerate(li[i]):
        if j:
            if n in used or n in l1:
                return False
            elif n not in tree[nest-1] and n not in ret:
                ret.append(n)
    return ret


N = int(input())
li = []
for _ in range(N):
    li.append(list(map(int,list(input()))))
    
max_nest = 0
for i in range(N):
    tree = [[]]
    used = []
    tree.append([i])
    nest = 1
    while True:
        ret = f1(tree[nest])
        nest += 1
        if ret == False:
            break
        elif ret != []:
            tree.append(ret)
            used.extend(tree[nest-2])
        else:
            if max_nest < nest:
                max_nest = nest
            break
        
print(max_nest-1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

def f1(l1):
    ret = []
    for i in l1:
      for n,j in enumerate(li[i]):
        if j == 1:
            if n in used or n in l1:
                return False
            elif n in tree[nest-1]:
            	pass
            else:
                ret.append(n)
    return list(set(ret))


N = int(input())
li = []
for _ in range(N):
    li.append(list(map(int,list(input()))))
    
max_nest = 0
for i in range(N):
    tree = [[]]
    used = []
    tree.append([i])
    nest = 1
    while True:
        ret = f1(tree[nest])
        nest += 1
        if ret == False:
            break
        elif ret != []:
            tree.append(ret)
            used.extend(tree[nest-2])
        else:
            if max_nest < nest:
                max_nest = nest
            break
        
print(max_nest-1)

Fixed submission:
def f1(l1):
    ret = []
    for i in l1:
      for n,j in enumerate(li[i]):
        if j:
            if n in used or n in l1:
                return False
            elif n not in tree[nest-1] and n not in ret:
                ret.append(n)
    return ret


N = int(input())
li = []
for _ in range(N):
    li.append(list(map(int,list(input()))))
    
max_nest = 0
for i in range(N):
    tree = [[]]
    used = []
    tree.append([i])
    nest = 1
    while True:
        ret = f1(tree[nest])
        nest += 1
        if ret == False:
            break
        elif ret != []:
            tree.append(ret)
            used.extend(tree[nest-2])
        else:
            if max_nest < nest:
                max_nest = nest
            break
        
print(max_nest-1)