Buggy python submission (verdict: Runtime Error):
INFTY = 10**8+10
N,M = map(int,input().split())
A = {}
for i in range(1,M+1):
    a,b = map(int,input().split())
    C = list(map(int,input().split()))
    A[i] = (a,C)
C = {}
for i in range(1,M+1):
    for j in A[i][1]:
        if j not in C:
            C[j] = 0
        C[j] += 1
if len(C)==N:
    dp = [[INFTY for _ in range(2**N)] for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(1,M+1):
        for S in range(2**N):
            dp[i][S] = dp[i-1][S]
            for a in A[i][1]:
                dp[i][S] = min(dp[i-1][S&~a]+A[i][0])
    print(dp[M,2**N-1])
else:
    print(-1)

Fixed submission:
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
INFTY = 10**11
dp = [[INFTY for S in range(2**N)] for _ in range(M+1)]
for j in range(M+1):
    dp[j][0] = 0
for j in range(M):
    for S in range(2**N):
        y = 0
        for x in G[j][1]:
            y += 2**(x-1)
        dp[j+1][S] = min(dp[j][S],dp[j][S&(~y)]+G[j][0])
a =dp[M][2**N-1]
if a>=INFTY:
    print(-1)
else:
    print(a)

Buggy python submission (verdict: Runtime Error):
INFTY = 10**8+10
N,M = map(int,input().split())
A = {}
for i in range(1,M+1):
    a,b = map(int,input().split())
    C = list(map(int,input().split()))
    A[i] = (a,C)
C = {}
for i in range(1,M+1):
    for j in A[i][1]:
        if j not in C:
            C[j] = 0
        C[j] += 1
if len(C)==N:
    dp = [[INFTY for _ in range(2**N)] for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(1,M+1):
        for S in range(2**N):
            dp[i][S] = dp[i-1][S]
            for a in A[i][1]:
                dp[i][S] = min(dp[i-1][S&~a]+A[i][0])
    print(dp[M,2**N-1])
else:
    print(-1)

Fixed submission:
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
INFTY = 10**11
dp = [[INFTY for S in range(2**N)] for _ in range(M+1)]
for j in range(M+1):
    dp[j][0] = 0
for j in range(M):
    for S in range(2**N):
        y = 0
        for x in G[j][1]:
            y += 2**(x-1)
        dp[j+1][S] = min(dp[j][S],dp[j][S&(~y)]+G[j][0])
a =dp[M][2**N-1]
if a>=INFTY:
    print(-1)
else:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
A = {S:{tuple(G[j][1]):[0] for j in range(M)} for S in product((0,1),repeat=N) }
for S in product((0,1),repeat=N):
    for j in range(M):
        B = [0 for _ in range(N)]
        for x in G[j][1]:
            B[x-1] = 1
        C = list(S[:])
        for i in range(N):
            if C[i]==1 and B[i]==1:
                C[i] = 0
        A[S][tuple(G[j][1])] = tuple(C)
INFTY = 10**11
dp = {j:{S:INFTY for S in product((0,1),repeat=N)} for j in range(M+1)}
for j in range(M+1):
    dp[j][tuple([0 for _ in range(N)])] = 0
for j in range(M):
    for S in product((0,1),repeat=N):
        dp[j+1][S] = min(dp[j][S],dp[j][A[S][tuple(G[j][1])]]+G[j][0])
s = tuple([1 for _ in range(N)])
a =dp[M][s]
if a>=INFTY:
    print(-1)
else:
    print(a)

Fixed submission:
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
INFTY = 10**11
dp = [[INFTY for S in range(2**N)] for _ in range(M+1)]
for j in range(M+1):
    dp[j][0] = 0
for j in range(M):
    for S in range(2**N):
        y = 0
        for x in G[j][1]:
            y += 2**(x-1)
        dp[j+1][S] = min(dp[j][S],dp[j][S&(~y)]+G[j][0])
a =dp[M][2**N-1]
if a>=INFTY:
    print(-1)
else:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
INFTY = 10**11
dp = {j:{S:INFTY for S in product((0,1),repeat=N)} for j in range(M+1)}
for j in range(M+1):
    dp[j][tuple([0 for _ in range(N)])] = 0
for j in range(M):
    for S in product((0,1),repeat=N):
        A = [0 for _ in range(N)]
        for x in G[j][1]:
            A[x-1] = 1
        B = list(S[:])
        for i in range(N):
            if B[i]==1 and A[i]==1:
                B[i] = 0
        dp[j+1][S] = min(dp[j][S],dp[j][tuple(B)]+G[j][0])
s = tuple([1 for _ in range(N)])
a =dp[M][s]
if a>=INFTY:
    print(-1)
else:
    print(a)

Fixed submission:
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
INFTY = 10**11
dp = [[INFTY for S in range(2**N)] for _ in range(M+1)]
for j in range(M+1):
    dp[j][0] = 0
for j in range(M):
    for S in range(2**N):
        y = 0
        for x in G[j][1]:
            y += 2**(x-1)
        dp[j+1][S] = min(dp[j][S],dp[j][S&(~y)]+G[j][0])
a =dp[M][2**N-1]
if a>=INFTY:
    print(-1)
else:
    print(a)