calculating maximal cut from given graph