fixed graph algorithm