我的代码适用于所有测试用例。然而,当我将它提交给SPOJ时,它会显示NZEC运行时错误。
http://www.spoj.com/problems/BUGLIFE/
def dfs(graph, start, visited = None, parent = None):
if visited == None:
visited = set()
visited.add(start)
for num in graph[start]:
if num not in visited:
visited.add(num)
if dfs(graph,num,visited,start):
return True
else:
if num != parent:
return True
return False
tc = int(raw_input())
for i in range(1, tc+1):
yo = {}
s = raw_input()
n, r = map(int, s.split())
for j in range(r):
s = raw_input()
p, q = map(int, s.split())
yo[p] = yo.get(p,[]) + [q]
yo[q] = yo.get(q,[]) + [p]
start = q
if dfs(yo, start):
print "Scenario #%d:" %(i)
print "Suspicious bugs found!"
else:
print "Scenario #%d:" %(i)
print "No suspicious bugs found!"