12-01 Weighted
WeightedGraph Class
Make a WeightedGraph subclass of your Graph class. (Just copy and edit if you’re not interested in subclassing.)
self.weights[(a,b)] == wt
means the edge from a to b has weightwt
.- The weights dictionary should be symmetric (just like the edges), so every time you add a weight from a to b, you should put the same weight from b to a.
Reader for WeightedGraph
Make a reader for your WeightedGraph class. The input should have this form:
NVERT 3
0 1 2
1
2
WEIGHTS 2
0 1 100
0 2 200