求任意两点之间最短的距离思路

首先维护一张两点之间的表
tmp:

a b
1 2

insert into tmp
select * from tmp t
where not exists (
select 1 from tmp where t.b=#{a} and t.a=#{b}
)
and not exists (
select 1 from tmp where t.a=#{a} and t.b=#{b}
);
保证任意两点之间只会存在一条记录 互为相反的也存一条
然后
加上递归算法就能实现求任意两点之间最短的距离

原文地址:https://www.cnblogs.com/LoveShare/p/14468127.html