Minimum Spanning Tree by murky-satyr

M:=Dictionary new.
stdin linesDo:[:l|M add:(l=~'\d+')match asNumber->l].1to:2e2do:[:i|M at:i ifPresent:[:e|(X:=(E:=e subStrings collect:[:v|M at:v ifAbsent:[{v}asSet]])first+E second)do:[:v|M at:v put:X].R:='F '.X=(E at:2)or:[R:='T '].(R,e)displayNl]]

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top