Buggy python submission (verdict: Time Limit Exceeded):
# O(MN + 4^N) 解
# 参考: https://twitter.com/ei1333/status/1177951676818325504
def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    dp = [float("inf")] * (1<<N)
    for _ in range(M):
        a, _ = map(int, input().split())
        C = list(map(int, input().split()))
        s = 0
        for c in C:
            s |= 1 << c-1
        dp[s] = min(dp[s], a)
    for i in range(1<<N):
        for j, dp_j in enumerate(dp):
            dp[i|j] = min(dp[i|j], dp[i]+dp_j)
    ans = dp[-1]
    print(ans if ans!=float("inf") else -1)

main()



Fixed submission:
N, M = map(int, input().split())
A = []
C = []
for _ in range(M):
    a, _ = map(int, input().split())
    A.append(a)
    C_ = list(map(int, input().split()))
    c = 0
    for c_ in C_:
        c |= 1<<c_-1
    C.append(c)
dp = [float("inf")] * (1<<N)
dp[0] = 0
for a, c in zip(A, C):
    dp_new = dp[:]
    for s, d in enumerate(dp):
        dp_new[s|c] = min(d+a, dp_new[s|c])
    dp = dp_new
#print(dp)
ans = dp[(1<<N)-1]
print(ans if ans != float("inf") else -1)

Buggy python submission (verdict: Time Limit Exceeded):
# O(MN + 4^N) 解
# 参考: https://twitter.com/ei1333/status/1177951676818325504
def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    dp = [float("inf")] * (1<<N)
    for _ in range(M):
        a, _ = map(int, input().split())
        C = list(map(int, input().split()))
        s = 0
        for c in C:
            s |= 1 << c-1
        dp[s] = min(dp[s], a)
    for i in range(1<<N):
        for j in range(1<<N):
            dp[i|j] = min(dp[i|j], dp[i]+dp[j])
    ans = dp[-1]
    print(ans if ans!=float("inf") else -1)

main()


Fixed submission:
N, M = map(int, input().split())
A = []
C = []
for _ in range(M):
    a, _ = map(int, input().split())
    A.append(a)
    C_ = list(map(int, input().split()))
    c = 0
    for c_ in C_:
        c |= 1<<c_-1
    C.append(c)
dp = [float("inf")] * (1<<N)
dp[0] = 0
for a, c in zip(A, C):
    dp_new = dp[:]
    for s, d in enumerate(dp):
        dp_new[s|c] = min(d+a, dp_new[s|c])
    dp = dp_new
#print(dp)
ans = dp[(1<<N)-1]
print(ans if ans != float("inf") else -1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = []
C = []
for _ in range(M):
    a, _ = map(int, input().split())
    A.append(a)
    C_ = list(map(int, input().split()))
    c = 0
    for c_ in C_:
        c |= 1<<c_-1
    C.append(c)
dp = [float("inf")] * (1<<N)
dp[0] = 0
for a, c in zip(A, C):
    dp_new = dp[:]
    for s, d in enumerate(dp):
        dp_new[s|c] = min(d+a, dp_new[s|c])
    dp = dp_new
#print(dp)
ans = dp[(1<<N)-1]
print(ans if ans != float("inf") else -1)


Fixed submission:
N, M = map(int, input().split())
A = []
C = []
for _ in range(M):
    a, _ = map(int, input().split())
    A.append(a)
    C_ = list(map(int, input().split()))
    c = 0
    for c_ in C_:
        c |= 1<<c_-1
    C.append(c)
dp = [float("inf")] * (1<<N)
dp[0] = 0
for a, c in zip(A, C):
    dp_new = dp[:]
    for s, d in enumerate(dp):
        dp_new[s|c] = min(d+a, dp_new[s|c])
    dp = dp_new
#print(dp)
ans = dp[(1<<N)-1]
print(ans if ans != float("inf") else -1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = []
C = []
for _ in range(M):
    a, _ = map(int, input().split())
    A.append(a)
    C_ = list(map(int, input().split()))
    c = 0
    for c_ in C_:
        c |= 1<<c_-1
    C.append(c)
dp = [float("inf")] * (1<<N)
dp[0] = 0
for a, c in zip(A, C):
    dp_new = dp[:]
    for s, d in enumerate(dp):
        dp_new[s|c] = min(d+a, dp_new[s|c])
    dp = dp_new
#print(dp)
ans = dp[(1<<N)-1]
print(ans if ans != float("inf") else -1)


Fixed submission:
N, M = map(int, input().split())
A = []
C = []
for _ in range(M):
    a, _ = map(int, input().split())
    A.append(a)
    C_ = list(map(int, input().split()))
    c = 0
    for c_ in C_:
        c |= 1<<c_-1
    C.append(c)
dp = [float("inf")] * (1<<N)
dp[0] = 0
for a, c in zip(A, C):
    dp_new = dp[:]
    for s, d in enumerate(dp):
        dp_new[s|c] = min(d+a, dp_new[s|c])
    dp = dp_new
#print(dp)
ans = dp[(1<<N)-1]
print(ans if ans != float("inf") else -1)