Implementation of sugiyama algorithm