Python Runtime Error

0
0

Hiho 题目号为1136

程序返回结果为Runtime Error,一开始用的递归,以为是超过了调用上限,后来改成了现在的循环结构,可是结果仍然返回 Runtime Error。求求大神看下哪里有问题?看了许多遍,没有看出哪里的问题,不胜感激。

RESULT = []
T = int( raw_input())
for index in range(T):
    initSigns = []  # to store the init signs
    Order = []      # to store the init order of the modules
    Modules = dict()    # key : module , value : results generates
    visitTimes = dict() # key : module , value : visit times
    visitStack = []     # to store the rest modules to visit

    (N,M) = (int(x) for x in raw_input().split())
    initSigns = [int(x) for x in raw_input().split()]
    for nIndex in range(N):     #explain each modules and their results
        inputArr = [int(x) for x in raw_input().split()]
        if len(inputArr) > 2:
            Modules[inputArr[0]] = inputArr[2:] 
            visitTimes[inputArr[0]] = 0
            Order.append(inputArr[0])

    for sign in initSigns:      # push the init signs
        visitStack.append(sign)
        visitTimes[sign] += 1

    while True:
        if len(visitStack) == 0:
            break
        for sign in Modules[visitStack.pop()]:  
            if sign in Modules:     #if this sign do exist
                visitStack.append(sign)
                visitTimes[sign] += 1

    itemRes = []
    for sign in Order:
        itemRes.append(visitTimes[sign] % 142857)
    RESULT.append(itemRes)

for res in RESULT:
    for j in range(len(res)-1):
        print res[j],   #print without a new line when have a comma
    print res[-1]

0 answer(s)

write answer 切换为英文 切换为中文


转发分享