Implement edge-weighted graph