implementation of an undirected graph with weight in java