translate input into weighted graph object