function [distance, path] = Dijk(w,start,aim)
% w-权值矩阵,start-起点,aim-终点
n=length(w);% 节点数
D=w(start,:);
visit=ones(1:n); visit(start)=0;
parent =zeros(1,n);% 记录每个节点的上一个节点
path=[];
for i=1:n-1;
temp=[];
for j=1:n
if visit(j)
temp =[temp inf];
end
end
[value,index]=min(temp);
visit(index)=0;
for k=1:n;
if D(k)>D(index)+ w(index,k)
D(k)=D(index)+ w(index,k);
parent(k)=index;
end
end
end
distance=D(aim);
t=aim;
while t~=start && t>0
path =[t,path];
p=parent(t);t=p;
end
path =[start,path];
end