connected graph optimised