compute balance of graphs