const townRelations = `洛阳-敦煌,28,129|嵩山,159,287|雁南,287,127
苏州-镜湖,32,162|西湖,182,287|太湖,182,32
楼兰-大苑,20,143|塔里木,161,307
大理-剑阁,27,151|洱海,159,287|无量山,291,151
南诏-苗疆,107,286|石林,281,45
南海-琼州,287,175|武夷,32,36
长白山-黄龙府,287,72|草原,32,269
束河古镇-苍山,26,286
琼州-南海,280,287
大苑-楼兰,194,233
嵩山-洛阳,33,55|太湖,287,247
太湖-嵩山,91,23|苏州,216,281
敦煌-洛阳,286,144|剑阁,231,286
剑阁-敦煌,105,38|大理,35,287
镜湖-苏州,286,43|武当山,28,234|无量山,36,286
无量山-镜湖,283,77|大理,32,175
草原-长白山,271,32|雁南,287,257|水晶洞,64,194|辽西,119,32
辽西-草原,61,297
水晶洞-草原,231,236
雁南-草原,32,57|摩崖洞,34,39|雁北,247,32|洛阳,265,287
雁北-雁南,229,280
摩崖洞-雁南,22,235
黄龙府-长白山,48,288
苍山-束河古镇,164,55|洱海,287,57
洱海-苍山,32,155|石林,32,281
武夷-南海,248,287|梅岭,284,181|黄龙府,96,44|西湖,36,32
西湖-武夷,265,286|苏州,33,51|夜西湖,92,43|山洞船坞,42,227
黄龙府-武夷,110,229
梅岭-武夷,32,274
琼州-南海,280,287
石林-南诏,33,250|洱海,269,128|玉溪,113,34|盐湖,39,274
苗疆-南诏,69,32
玉溪-石林,35,46`;
function parseTownRelations (townRelations) {
const relations = {};
const lines = townRelations.trim ().split ( lines.forEach (line => {
const [source, targets] = line.split ( if (targets) {
const branches = targets.split ( relations[source] = branches.map (branch => {
const [target, , ] = branch.split ( return target;
});
} else {
relations[source] = [];
}
});
return relations;
}
function findPath (graph, start, end, path = [], visited = new Set ()) {
path.push (start);
visited.add (start);
if (start === end) {
return Array.from (path.join ( }
const neighbors = graph[start];
console.log ( if (neighbors) {
for (const neighbor of neighbors) {
if (!visited.has (neighbor)) {
findPath (graph, neighbor, end, path.slice (), visited);
}
}
}
}
const townGraph = parseTownRelations (townRelations);
findPath (townGraph,