from collections import defaultdict def dfs(node, parent, dist, lengths): for neighbor, weight in graph[node]: if neighbor != parent: lengths[neighbor] = dist + weight dfs(neighbor, node, lengths[neighbor], lengths) W, E = map(int, input().split()) w_stations = [i for i in range(1, W+1)] e_stations = [i for i in range(W+1, W+E+1)] graph = defaultdict(list) for _ in range(W+E-1): u, v, w = map(int, input().split()) graph[u].append((v, w)) graph[v].append((u, w)) w_lengths = defaultdict(int) e_lengths = defaultdict(int) for node in w_stations: dfs(node, 0, 0, w_lengths) for node in e_stations: dfs(node, 0, 0, e_lengths) options = [] for w_node in w_stations: for e_node in e_stations: length = w_lengths[w_node] + e_lengths[e_node] for node in w_stations: if node != w_node: length += w_lengths[node] for node in e_stations: if node != e_node: length += e_lengths[node] options.append(length / (W+E-1))