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

首先维护一张两点之间的表
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=#
)
and not exists (
select 1 from tmp where t.a=#{a} and t.b=#
);
保证任意两点之间只会存在一条记录 互为相反的也存一条
然后
加上递归算法就能实现求任意两点之间最短的距离
posted @ 2021-03-02 11:36  DiligentCoder  阅读(457)  评论(0编辑  收藏  举报