728x90
๋ฌธ์
ํ์ด
๋นํธ ๋ง์คํน์ ์ฌ์ฉํ์ฌ ์ ๋ ฅ
n, m = map(int, input().split())
arr = [0b0000000000] * (m + 1)
for i in range(1, m + 1):
question = list(map(int, input().split()))[1:]
for q in question:
arr[i] |= (1 << q)
๋ธ๋ฃจํธ ํฌ์ค๋ฅผ ์ํด m + 1๋ฒ ๋ฐ๋ณต
for ans in range(1, m + 1):
tmp = set()
for i in range(len(arr)):
if arr[i] == 2 ** (n + 1) - 2:
print(ans)
exit()
for j in range(i + 1, len(arr)):
tmp.add(arr[i] | arr[j])
arr = list(tmp)
์ฝ๋
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
arr = [0b0000000000] * (m + 1)
for i in range(1, m + 1):
question = list(map(int, input().split()))[1:]
for q in question:
arr[i] |= (1 << q)
for ans in range(1, m + 1):
tmp = set()
for i in range(len(arr)):
if arr[i] == 2 ** (n + 1) - 2:
print(ans)
exit()
for j in range(i + 1, len(arr)):
tmp.add(arr[i] | arr[j])
arr = list(tmp)
print(-1)
๋ง๋ฌด๋ฆฌ
๋นํธ ๋ง์คํน์ ๊ณต๋ถํ๊ธฐ ์ํด ํ์ ๋ฌธ์
728x90