腾讯笔试: 哪位大佬帮我看看 为什么提示的是语法错误呢?
n,m,k = list(map(int,input().strip().split())) from collections import defaultdict d = defaultdict(list) for _ in range(m): a,b,c = list(map(int,input().strip().split())) d[a].append([b,c]) d[b].append([a,c]) for _ in range(k): a,b = list(map(int,input().strip().split())) d[a].append([b,0]) #print(d) def helper(num,shang): #print(num,shang) #print(num) if num == n: return 0 res = 100000000 for i in d[num]: if i[0]!=shang: t = helper(i[0],num) #print(i,t) res = min(res,t+i[1]) return res a = helper(1,-1) if a == 100000000: print(-1) else: print(a)
全部评论
(1) 回帖