Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

line = input()
v, e = list(map(int, line.split()))
edge = []
for _ in range(0, e):
    line = input()
    s, t, w = list(map(int, line.split()))
    edge += [[s, t, w]]

def solve(v, edge):
    q = []
    vtx = set([i for i in range(0, v)])
    for s, t, w in edge:
        heappush(q, (w, (s, t)))
    vn = set([0])
    en = []
    cost = 0
    while vn != vtx:
        w = s = t = 0
        qq = []
        while q:
            w, st = heappop(q)
            s, t = st
            if s in vn and t not in vn:
                break
            if s not in vn and t in vn:
                s, t = t, s
                break
            qq += [[s, t, w]]
        for s, t, w in qq:
            heappush(q, (w, (s, t)))
        vn.add(t)
        en += [(s, t)]
        cost += w
    return cost
        
print(solve(v, edge))


Fixed submission:
from heapq import heappush, heappop

line = input()
v, e = list(map(int, line.split()))
edge = {}
edge[0] = [[0, 0]]
for _ in range(0, e):
    line = input()
    s, t, w = list(map(int, line.split()))
    if s not in edge:
        edge[s]  = [[t, w]]
    else:
        edge[s] += [[t, w]]
    if t not in edge:
        edge[t]  = [[s, w]]
    else:
        edge[t] += [[s, w]]

def solve(v, edge):
    q = []
    vtx = set([i for i in range(0, v)])
    for t, w in edge[0]:
        heappush(q, (w, 0, t))
    vn = set([0])
    en = []
    cost = 0
    while len(vn) < v:
        w = s = t = 0
        qq = []
        while q:
            w, s, t = heappop(q)
            if s in vn and t not in vn:
                s, t = t, s
                break
            if s not in vn and t in vn:
                break
        vn.add(s)
        en += [(s, t)]
        cost += w
        for t, w in edge[s]:
            heappush(q, (w, s, t))
    return cost
        
print(solve(v, edge))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

line = input()
v, e = list(map(int, line.split()))
edge = []
for _ in range(0, e):
    line = input()
    s, t, w = list(map(int, line.split()))
    edge += [[s, t, w]]

def solve(v, edge):
    q = []
    vtx = set([i for i in range(0, v)])
    for s, t, w in edge:
        heappush(q, (w, (s, t)))
    vn = set([0])
    en = []
    cost = 0
    while vn != vtx:
        w = s = t = 0
        qq = []
        while q:
            w, st = heappop(q)
            s, t = st
            if s in vn and t not in vn:
                break
            if s not in vn and t in vn:
                s, t = t, s
                break
            qq += [[s, t, w]]
        vn.add(t)
        en += [(s, t)]
        cost += w
        for s, t, w in qq:
            heappush(q, (w, (s, t)))
    return cost
        
print(solve(v, edge))


Fixed submission:
from heapq import heappush, heappop

line = input()
v, e = list(map(int, line.split()))
edge = {}
edge[0] = [[0, 0]]
for _ in range(0, e):
    line = input()
    s, t, w = list(map(int, line.split()))
    if s not in edge:
        edge[s]  = [[t, w]]
    else:
        edge[s] += [[t, w]]
    if t not in edge:
        edge[t]  = [[s, w]]
    else:
        edge[t] += [[s, w]]

def solve(v, edge):
    q = []
    vtx = set([i for i in range(0, v)])
    for t, w in edge[0]:
        heappush(q, (w, 0, t))
    vn = set([0])
    en = []
    cost = 0
    while len(vn) < v:
        w = s = t = 0
        qq = []
        while q:
            w, s, t = heappop(q)
            if s in vn and t not in vn:
                s, t = t, s
                break
            if s not in vn and t in vn:
                break
        vn.add(s)
        en += [(s, t)]
        cost += w
        for t, w in edge[s]:
            heappush(q, (w, s, t))
    return cost
        
print(solve(v, edge))

Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop

line = input()
v, e = list(map(int, line.split()))
edge = {}
for _ in range(0, e):
    line = input()
    s, t, w = list(map(int, line.split()))
    if s not in edge:
        edge[s]  = [[t, w]]
    else:
        edge[s] += [[t, w]]
    if t not in edge:
        edge[t]  = [[s, w]]
    else:
        edge[t] += [[s, w]]

def solve(v, edge):
    q = []
    vtx = set([i for i in range(0, v)])
    for t, w in edge[0]:
        heappush(q, (w, 0, t))
    vn = set([0])
    en = []
    cost = 0
    while len(vn) < v:
        w = s = t = 0
        qq = []
        while q:
            w, s, t = heappop(q)
            if s in vn and t not in vn:
                s, t = t, s
                break
            if s not in vn and t in vn:
                break
        vn.add(s)
        en += [(s, t)]
        cost += w
        for t, w in edge[s]:
            heappush(q, (w, s, t))
    return cost
        
print(solve(v, edge))


Fixed submission:
from heapq import heappush, heappop

line = input()
v, e = list(map(int, line.split()))
edge = {}
edge[0] = [[0, 0]]
for _ in range(0, e):
    line = input()
    s, t, w = list(map(int, line.split()))
    if s not in edge:
        edge[s]  = [[t, w]]
    else:
        edge[s] += [[t, w]]
    if t not in edge:
        edge[t]  = [[s, w]]
    else:
        edge[t] += [[s, w]]

def solve(v, edge):
    q = []
    vtx = set([i for i in range(0, v)])
    for t, w in edge[0]:
        heappush(q, (w, 0, t))
    vn = set([0])
    en = []
    cost = 0
    while len(vn) < v:
        w = s = t = 0
        qq = []
        while q:
            w, s, t = heappop(q)
            if s in vn and t not in vn:
                s, t = t, s
                break
            if s not in vn and t in vn:
                break
        vn.add(s)
        en += [(s, t)]
        cost += w
        for t, w in edge[s]:
            heappush(q, (w, s, t))
    return cost
        
print(solve(v, edge))