# Time: O(n^2 * 2^n) # Space: O(n * 2^n) import itertools # combination based dp class Solution(object): def maximumCost(self, n, highways, k): """ :type n: int :type highways: List[List[int]] :type k: int :rtype: int """ if k+1 > n: # optionally optimize return -1 adj = [[] for _ in xrange(n)] for c1, c2, t in highways: adj[c1].append((c2, t)) adj[c2].append((c1, t)) result = -1 if k != 1 else 0 dp = [[0, []] for _ in xrange((1< n: # required to optimize, otherwise, TLE or MLE return -1 adj = [[] for _ in xrange(n)] for c1, c2, t in highways: adj[c1].append((c2, t)) adj[c2].append((c1, t)) result = -1 dp = [(u, 1<