You should somehow express that A is connected to B by 2 links if there is a C such that A is connected to C directly and C is connected to B directly. So you need to create an additional rule called 'link2' or something appropriate to express 'connected by 2 direct links'
Also, take care of cycles. You'll see that a naive approach to this problem would report each city as being connected to itself by 2 links, because A - B and B - A also fulfill the rule above.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.