Add support for weighted graphs.