added wagner algorithm