def int0(n): return int(n)-1 N = int(input()) # 街の数 C = int(input()) # 所持金 V = int(input()) # 道の数 S = list(map(int0, input().split())) # S->T T = list(map(int0, input().split())) # Y = list(map(int, input().split())) # cost[S][T] M = list(map(int, input().split())) # time[S][T] cost = [[301 for _ in range(N)] for _ in range(N)] time = [[50*1001 for _ in range(N)] for _ in range(N)] for i in range(V): cost[S[i]][T[i]] = Y[i] time[S[i]][T[i]] = M[i] for i in range(N): for j in range(N): for k in range(N): time[i][j] == min(time[i][j], time[i][j]+time[k][j]) ans = [] for j in range(N): if time[0][j] == 50050: continue ans.append(time[0][j]) print(max(ans))