added function to parse a weighted graph from a string