def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot else: parent[yroot] = xroot rank[xroot] += 1 def kruskal(N, edges_with_weights): result = [] i, e = 0, 0 parent = [] rank = [] for node in range(N): parent.append(node) rank.append(0) edges_with_weights.sort(key=lambda x: x[2]) while e < N - 1: if i >= len(edges_with_weights): return float('inf') u, v, w = edges_with_weights[i] i = i + 1 x = find(parent, u) y = find(parent, v) if x != y: e = e + 1 result.append((u, v, w)) union(parent, rank, x, y) return sum(weight for _, _, weight in result) def main(): N, M, K = map(int, input().split()) edges = [] for _ in range(M): a, b, c, d = map(int, input().split()) edges.append((a - 1, b - 1, c, d)) edges_with_weights = [(a, b, c) for (a, b, c, d) in edges] mst_weight = kruskal(N, edges_with_weights) score = K * mst_weight - sum(d * x for (_, _, x, d) in edges) print("Calculated MST Weight:", mst_weight) print("Calculated Score:", score) if __name__ == "__main__": main()