2013-04-17 14:34:39 +08:00

46 lines
732 B
Python

ff = open('../network.txt', 'r')
nnn = ff.readlines()
ff.close()
inf = 10 ** 10
def stolis(s):
mid = s.split(',')
out = []
for i in mid:
if i.isdigit():
out.append(int(i))
else:
out.append(inf)
return out
hole = 0
net = []
for i in nnn:
tmp = stolis(i.strip())
for j in tmp:
if j < inf:
hole += j
net.append(tmp)
#print net
have = [0]
nothave = range(1, len(net))
total = 0
while len(nothave) > 0:
choose = [inf, 0]
node = 0
it = 0
for node in nothave:
for it in have:
if net[node][it] < choose[0]:
choose = [net[node][it], node]
if choose[0] < inf:
have.append(choose[1])
nothave.remove(choose[1])
total += choose[0]
print hole / 2 - total