Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = []
v = 0
for _ in range(M):
    a, b = map(int, input().split())
    l = sum([1 << (int(v) - 1) for v in input().split()])
    L.append([a, b, l])
    v = v | l
if v != (1 << N) - 1:
     print(-1)
     exit()

dp = [[10 ** 18 for _ in range(1 << N)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(M):
     for j in range(1 << N):
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

          dp[i + 1][j | L[i][2]] =  min(dp[i + 1][j | L[i][2]], dp[i][j] + L[i][0])

print(dp[M][(1 << N) - 1])

Fixed submission:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = []
v = 0
for _ in range(M):
    a, b = map(int, input().split())
    l = sum([1 << (int(v) - 1) for v in input().split()])
    L.append([a, b, l])
    v = v | l
if v != (1 << N) - 1:
     print(-1)
     exit()

dp = [[10 ** 18 for _ in range(1 << N)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(M):
     for j in range(1 << N):
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

          dp[i + 1][j | L[i][2]] =  min(dp[i + 1][j | L[i][2]], dp[i][j] + L[i][0])

print(dp[M][(1 << N) - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = [[int(v) for v in input().split()] for _ in range(M * 2)]

ans = 10 ** 18
for i in range(1 << M):
    a = []
    for j in range(M):
        if (i >> j) & 1:
            a.append(j)

    s = set()
    p = 0
    for v in a:
        s = s | set(L[v * 2 + 1])
        p += L[v * 2][0]

    if len(s) != N:
        continue

    ans = min(ans, p)

if ans == 10 ** 18:
    print(-1)
else:
    print(ans)

Fixed submission:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = []
v = 0
for _ in range(M):
    a, b = map(int, input().split())
    l = sum([1 << (int(v) - 1) for v in input().split()])
    L.append([a, b, l])
    v = v | l
if v != (1 << N) - 1:
     print(-1)
     exit()

dp = [[10 ** 18 for _ in range(1 << N)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(M):
     for j in range(1 << N):
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

          dp[i + 1][j | L[i][2]] =  min(dp[i + 1][j | L[i][2]], dp[i][j] + L[i][0])

print(dp[M][(1 << N) - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

t = set([v for v in range(1, N + 1)])
L = [None] * M
for i in range(M):
    A, B, = map(int, input().split())
    C = [int(v) for v in input().split()]
    
    L[i] = (A, C)
    t = t - set(C)

if len(t) > 0:
    print(-1)
    exit()

ans = 10 ** 18
for i in range(1, 1 << M):
    t = set()

    for j in range(M):
        if (i >> j) & 1:
            t.add(j)

    m = set([v for v in range(1, N + 1)])
    score = 0
    for p in t:
        a = L[p]
        score += a[0]
        m = m - set(a[1])

    if len(m) == 0:
        ans = min(ans, score)

print(ans)


Fixed submission:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = []
v = 0
for _ in range(M):
    a, b = map(int, input().split())
    l = sum([1 << (int(v) - 1) for v in input().split()])
    L.append([a, b, l])
    v = v | l
if v != (1 << N) - 1:
     print(-1)
     exit()

dp = [[10 ** 18 for _ in range(1 << N)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(M):
     for j in range(1 << N):
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

          dp[i + 1][j | L[i][2]] =  min(dp[i + 1][j | L[i][2]], dp[i][j] + L[i][0])

print(dp[M][(1 << N) - 1])

Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = [None] * M
for i in range(M):
    A, B, = map(int, input().split())
    C = [int(v) for v in input().split()]
    
    L[i] = (A, C)

ans = 10 ** 18
for i in range(1 << N):
    t = set()

    for j in range(N):
        if (i >> j) & 1:
            t.add(j)

    m = set([v for v in range(1, N + 1)])
    score = 0
    for p in t:
        a = L[p]
        score += a[0]
        m = m - set(a[1])

    if len(m) == 0:
        ans = min(ans, score)

if ans == 10 ** 18:
    print(-1)
else:
    print(ans)


Fixed submission:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = []
v = 0
for _ in range(M):
    a, b = map(int, input().split())
    l = sum([1 << (int(v) - 1) for v in input().split()])
    L.append([a, b, l])
    v = v | l
if v != (1 << N) - 1:
     print(-1)
     exit()

dp = [[10 ** 18 for _ in range(1 << N)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(M):
     for j in range(1 << N):
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

          dp[i + 1][j | L[i][2]] =  min(dp[i + 1][j | L[i][2]], dp[i][j] + L[i][0])

print(dp[M][(1 << N) - 1])