python一直re,但是在pycharm可以正常运行,没有报错

P4779 【模板】单源最短路径(标准版)

lijiu @ 2024-11-17 22:15:04

list_begin = []
list_end = []
list_length = []
list_first = [0,1,2,3]
c = float('inf')
list_out = [c,c,c,c]
k = 0
# 输入有向图的信息
def num(n,m,s):
    mi = 0
    list_first.remove(s-1)
    list_out[s - 1] = 0
    k = s - 1
    for i in range(m):
        u,v,w = map(int,input().split())
        list_begin.append(u)
        list_end.append(v)
        list_length.append(w)
#寻找最小的路径
    for i in range(n-1):
        for j in range(m):
            if list_begin[j] == s:
                count = j
                if mi + list_length[count] < list_out[list_end[j]-1]:
                    list_out[list_end[j]-1] = mi +list_length[j]
        com = c
        for a in list_first:
            if list_out[a]<com:
                com = list_out[a]
        mi = com
        b = list_out.index(com)
        list_first.remove(b)
        s = b+1
n,m,s = map(int,input().split())
num(n,m,s)
for l in list_out:
    print(l, end= ' ')

|