Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0

for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + a
        if score == float("inf"):
            continue

        ex_status = 0
        for j in box:
            ex_status += 1 << (j-1)
        now_status = i | ex_status

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])



Fixed submission:

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0
key_v = [float('inf')] * (1 << N)
for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    ex_status = 0
    for j in box:
        ex_status += 1 << (j-1)
    key_v[ex_status] = min(a, key_v[ex_status])

for key, val in enumerate(key_v):
    if val == float('inf'):
        continue
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + val
        if score == float("inf"):
            continue

        now_status = i | key

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])

Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0

for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + a

        ex_status = 0
        for j in box:
            ex_status += 1 << (j-1)
        now_status = i | ex_status

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])



Fixed submission:

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0
key_v = [float('inf')] * (1 << N)
for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    ex_status = 0
    for j in box:
        ex_status += 1 << (j-1)
    key_v[ex_status] = min(a, key_v[ex_status])

for key, val in enumerate(key_v):
    if val == float('inf'):
        continue
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + val
        if score == float("inf"):
            continue

        now_status = i | key

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])

Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())
C = {}
for i in range(1 << N):
    C[format(i, "012b")[::-1]] = 10**9
C["000000000000"] = 0
keys = []

for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    for i in range(1 << N):
        now_status = format(i, "012b")[::-1]
        score = C[now_status] + a

        ex_status = list(now_status)
        for j in box:
            ex_status[j-1] = "1"
        now_status = "".join(ex_status)

        if C[now_status] > score:
            C[now_status] = score

if C["1"*N+"0"*(12-N)] == 10**9:
    print(-1)
else:
    print(C["1"*N+"0"*(12-N)])



Fixed submission:

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0
key_v = [float('inf')] * (1 << N)
for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    ex_status = 0
    for j in box:
        ex_status += 1 << (j-1)
    key_v[ex_status] = min(a, key_v[ex_status])

for key, val in enumerate(key_v):
    if val == float('inf'):
        continue
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + val
        if score == float("inf"):
            continue

        now_status = i | key

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])

Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())
C = {}
for i in range(1 << N):
    C[format(i, "012b")[::-1]] = 10**9
C["000000000000"] = 0
keys = []

for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    for i in range(1 << N):
        now_status = format(i, "012b")[::-1]
        score = C[now_status] + a

        ex_status = list(now_status)
        for j in box:
            ex_status[j-1] = "1"
        now_status = "".join(ex_status)

        if C[now_status] > score:
            C[now_status] = score

if C["1"*N+"0"*(12-N)] == 10**9:
    print(-1)
else:
    print(C["1"*N+"0"*(12-N)])



Fixed submission:

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0
key_v = [float('inf')] * (1 << N)
for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    ex_status = 0
    for j in box:
        ex_status += 1 << (j-1)
    key_v[ex_status] = min(a, key_v[ex_status])

for key, val in enumerate(key_v):
    if val == float('inf'):
        continue
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + val
        if score == float("inf"):
            continue

        now_status = i | key

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, M = map(int, input().split())
keys = []
for i in range(M):
    a, b = map(int, input().split())
    keys.append((a, list(map(int, input().split()))))
C = Counter()
for i in range(1 << N):
    C[format(i, "012b")[::-1]] = 10**9
C["000000000000"] = 0
for a, b in keys:
    for i in range(1 << N):
        now_status = format(i, "012b")[::-1]
        score = C[now_status] + a

        ex_status = list(now_status)
        for j in b:
            ex_status[j-1] = "1"
        now_status = "".join(ex_status)

        if C[now_status] > score:
            C[now_status] = score

if C["1"*N+"0"*(12-N)] == 10**9:
    print(-1)
else:
    print(C["1"*N+"0"*(12-N)])



Fixed submission:

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0
key_v = [float('inf')] * (1 << N)
for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    ex_status = 0
    for j in box:
        ex_status += 1 << (j-1)
    key_v[ex_status] = min(a, key_v[ex_status])

for key, val in enumerate(key_v):
    if val == float('inf'):
        continue
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + val
        if score == float("inf"):
            continue

        now_status = i | key

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, M = map(int, input().split())
keys = []
for i in range(M):
    a, b = map(int, input().split())
    keys.append((a, list(map(int, input().split()))))
C = Counter()
for i in range(1 << N):
    C[format(i, "012b")[::-1]] = 10**9
C["000000000000"] = 0
for a, b in keys:
    for i in range(1 << N):
        now_status = format(i, "012b")[::-1]
        score = C[now_status] + a

        ex_status = list(now_status)
        for j in b:
            ex_status[j-1] = "1"
        now_status = "".join(ex_status)

        if C[now_status] > score:
            C[now_status] = score

if C["1"*N+"0"*(12-N)] == 10**9:
    print(-1)
else:
    print(C["1"*N+"0"*(12-N)])



Fixed submission:

N, M = map(int, input().split())

C = [float('inf')] * (1 << N)
C[0] = 0
key_v = [float('inf')] * (1 << N)
for j in range(M):
    a, b = map(int, input().split())
    box = list(map(int, input().split()))
    ex_status = 0
    for j in box:
        ex_status += 1 << (j-1)
    key_v[ex_status] = min(a, key_v[ex_status])

for key, val in enumerate(key_v):
    if val == float('inf'):
        continue
    for i in range(1 << N):
        now_status = i
        score = C[now_status] + val
        if score == float("inf"):
            continue

        now_status = i | key

        if C[now_status] > score:
            C[now_status] = score

if C[-1] == float("inf"):
    print(-1)
else:
    print(C[-1])