A solution to POJ 3259 Wormholes