暴力枚举+并查集
30pt
def union(x, y, s):
rootx = find(x, s)
rooty = find(y, s)
if rooty != rootx:
s[rootx] = rooty
return True
return False
def find(x, s):
if x != s[x]:
s[x] = find(s[x], s)
return s[x]
while True:
try:
n, m = map(int, input().split())
L = list(map(int, input().split()))
s = {i: i for i in L} # 使用字典初始化并查集
count = m
for i in range(m):
for j in range(i + 1, m): # 避免重复比较
if (L[i] & L[j]) == 0:
if union(L[i], L[j], s):
count -= 1
print(count)
except EOFError:
break