Runtime error with Python3

Правка en1, от jan25, 2018-06-04 00:43:09

Hi folks, I keep getting Runtime error with this implementation in Python3.6. Same implementation in C++11 is Accepted Pls comment if you find something off. Thanks! Here's the link to problem

n, m = map(int, input().split())
g = {v : [] for v in range(1, n + 1)}
for e in range(m):
    u, v = map(int, input().split())
    g[u].append(v)
    g[v].append(u)

glob_vis = set()
def bfs(v):
    vis = set([v])
    glob_vis.add(v)
    q = [v]
    qi, e = 0, 0
    while qi < len(q):
        v = q[qi]
        for u in g[v]:
            e += 1
            if u not in vis:
               vis.add(u)
               glob_vis.add(u)
               q.append(u)
        qi += 1
    return [e//2, len(vis)]

min_sep = 0
for v in range(1, n + 1):
    if v not in glob_vis:
        res = bfs(v)
        if res[0] == res[1] - 1:
            min_sep += 1

print (min_sep)
Теги python 3, runtime error, graphs, practise

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский jan25 2018-06-04 00:43:09 1050 Initial revision (published)