def solution(n, computers):
computers.sort(reverse=True)
ans = [] ; answer=0
for i in range(n):
a = []
for j in range(n):
if computers[i][j] == 1:
a.append(j+1)
if len(ans) == 0:
ans.append(a)
else:
k = 0
for j in range(len(ans)):
if len(set(a) & set(ans[j])) >= 1:
ans[j] = list(set(ans[j]) | set(a))
break
else:
k += 1
if k == len(ans):
ans.append(a)
# while True:
for i in range(len(ans)-1):
k = 0
for j in range(i+1,len(ans)):
if len(set(ans[i]) & set(ans[j])) >= 1:
ans[j] = list(set(ans[i]) | set(ans[j]))
ans[i] = ans[j] #list(set(ans[i]) | set(ans[j]))
break
else:
k += 1
if k == len(ans):
ans.append(a)
while ans:
a = ans.pop(0)
if a not in ans:
answer+=1
return answer