Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Dijkstras-algorithm/PARI-GP/dijkstras-algorithm.parigp
Normal file
19
Task/Dijkstras-algorithm/PARI-GP/dijkstras-algorithm.parigp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
shortestPath(G, startAt=1)={
|
||||
my(n=#G[,1],dist=vector(n,i,9e99),prev=dist,Q=2^n-1);
|
||||
dist[startAt]=0;
|
||||
while(Q,
|
||||
my(t=vecmin(vecextract(dist,Q)),u);
|
||||
if(t==9e99, break);
|
||||
for(i=1,#v,if(dist[i]==t && bittest(Q,i-1), u=i; break));
|
||||
Q-=1<<(u-1);
|
||||
for(i=1,n,
|
||||
if(!G[u,i],next);
|
||||
my(alt=dist[u]+G[u,i]);
|
||||
if (alt < dist[i],
|
||||
dist[i]=alt;
|
||||
prev[i]=u;
|
||||
)
|
||||
)
|
||||
);
|
||||
dist
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue