# Parse data
n,m,k = [int(i) for i in input().strip().split(' ')]
Road = []
bRoad = []
for _ in range(m):
Road.append([int(i) for i in input().strip().split(' ')])
for _ in range(k):
bRoad.append([int(i) for i in input().strip().split(' ')])
# check connectivity
def check(Road):
state = [i+1 for i in range(n)]
for i in range(len(Road)):
a = min(Road[i])
b = max(Road[i])
for j in range(n):
if state[j] == state[b-1]:
state[j] = state[a-1]
return set(state) == set([1])
def slove(Road,bRoad,i):
if i == len(bRoad) and check(Road):
return 0
elif i==len(bRoad):
return -1
r = bRoad[i][:2]
Road.append(r)
branch_alpha = bRoad[i][2]+slove(Road,bRoad,i+1)
Road.remove(r)
branch_beta = slove(Road,bRoad,i+1)
return min([i for i in [branch_alpha,branch_beta] if i !=-1])
print(slove(Road,bRoad,0))
简洁是挺简洁的,不过超时的比较严重,AC 9%,需要优化