graph builded and check end connection