implementation of weighted graph class