REM 見せてやるぜ…†本物のダイクストラ法†ってやつをよ…
REM なお動作は未検証
ACLS
XSCREEN 1
OPTION STRICT
OPTION DEFINT
VAR N,M
VAR X,Y,T
DIM LIST[3100],NODE[3100],COST[3100]
VAR LLAST
DIM HEAP[3100],HDIST[3100]
VAR HLAST
DIM D[100]
VAR INF=1000000
VAR I,J
VAR LOOK
VAR P
VAR ANS
INPUT N,M
LLAST=N
FILL D,INF,0,N
FOR I=1 TO M
INPUT X,Y,T
LIST[LLAST]=LIST[X]
LIST[X]=LLAST
NODE[LLAST]=Y
COST[LLAST]=T
LLAST=LLAST+1
NEXT I
HEAP[0]=0
HLAST=1
D[0]=0
WHILE HLAST
'POP
LOOK=HEAP[0]
IF HDIST[0]<D[LOOK] THEN D[LOOK]=HDIST[0]
HLAST=HLAST-1
T=HEAP[HLAST]
I=0
J=1+(heap[1]>heap[2])
while J<HLAST&&T>HEAP[J]
HEAP[I]=HEAP[J]
HDIST[I]=HDIST[J]
I=J
IF J*2+1<LAST&&HEAP[J*2+1]>HEAP[J*2+2] THEN
J=J*2+1
ELSE
J=J*2+1
ENDIF
WEND
HEAP[I]=T
P=LIST[LOOK]
T=D[LOOK]
WHILE P
IF T+COST[P]<D[NODE[P]] THEN
'PUSH
I=HLAST
J=(I-1)>>1
WHILE I>0&&HEAP[J]>N
HEAP[I]=HEAP[J]
HDIST[I]=HDIST[J]
I=J
J=(I-1)>>1
WEND
HEAP[I]=NODE[P]
HDIST[I]=T+COST[P]
HLAST=HLAST+1
ENDIF
P=LIST[P]
WEND
WEND
FOR I=0 TO N-1
ANS=MAX(ANS,D[I])
NEXT I
PRINT ANS