from heapq import * n, m = list(map(int, input().split())) A = list(map(int, input().split())) node = [[] for _ in range(n)] for _ in range(m): u, v, w = list(map(lambda x: int(x)-1, input().split())) w += 1 node[u].append((v, w)) inf = 1<<60 ans0 = inf+1 ans1 = 0 for s in range(n): D = [inf]*n D[s] = 0 hq = [] heappush(hq, (0, s)) while hq: cost, u = heappop(hq) if D[u] < cost: continue for v, w in node[u]: if D[v] > cost+w: D[v] = cost+w heappush(hq, (cost+w, v)) for v in range(n): if s == v: continue d = A[s]+A[v]+D[v] #print(s, v, d) if ans0 > d: ans0, ans1 = d, 1 elif ans0 == d: ans1 += 1 print(ans0, ans1)