reserve x,y,X for set,
  i,j,k,m,n for Nat,
  p for FinSequence of X,
  ii for Integer;
reserve G for Graph,
  pe,qe for FinSequence of the carrier' of G,
  p,q for oriented Chain of G,
  W for Function,
  U,V,e,ee for set,
  v1,v2,v3,v4 for Vertex of G;
reserve G for finite Graph,
  P,Q for oriented Chain of G,
  v1,v2,v3 for Vertex of G;
reserve G for finite oriented Graph,
  P,Q for oriented Chain of G,
  W for Function of (the carrier' of G), Real>=0,
  v1,v2,v3,v4 for Vertex of G;
reserve f,g,h for Element of REAL*,
  r for Real;
reserve G for oriented Graph,
  v1,v2 for Vertex of G,
  W for Function of (the carrier' of G), Real>=0;
reserve p,q for FinSequence of NAT,
  G for finite oriented Graph,
  P,Q,R for oriented Chain of G,
  W for Function of (the carrier' of G), Real>=0,
  v1,v2,v3, v4 for Vertex of G;

theorem
  f is_Input_of_Dijkstra_Alg G,n,W & v1=1 & 1 <> v2 & v2=i & n >= 1 & g=
(DijkstraAlgorithm(n)).f implies the carrier of G = UsedVx(g,n) \/ UnusedVx(g,n
  ) & (v2 in UsedVx(g,n) implies ex p,P st p is_simple_vertex_seq_at g,i,n & P
is_oriented_edge_seq_of p & P is_shortestpath_of v1,v2,W & cost(P,W)=g.(2*n+i))
  & (v2 in UnusedVx(g,n) implies not ex Q st Q is_orientedpath_of v1,v2)
proof
  assume that
A1: f is_Input_of_Dijkstra_Alg G,n,W and
A2: v1=1 and
A3: 1 <> v2 and
A4: v2=i and
A5: n >= 1 and
A6: g=(DijkstraAlgorithm(n)).f;
A7: Seg n=the carrier of G by A1;
  then reconsider VG=the carrier of G as non empty Subset of NAT by A5;
A8: f.(n+1) =0 by A1;
  set Ug=UsedVx(g,n), Vg=UnusedVx(g,n);
  set R=Relax(n), M=findmin(n), RM=repeat (R*M), cn=LifeSpan(R*M,f,n), mi=n*n+
  3*n+1;
A9: g = RM.cn.f by A6,Def5;
A10: Ug \/ Vg c= VG
  proof
    let x be object;
    assume
A11: x in Ug \/ Vg;
    per cases by A11,XBOOLE_0:def 3;
    suppose
      x in Ug;
      then ex k st x = k & k in dom g & 1 <= k & k <= n & g.k = -1;
      hence thesis by A7,FINSEQ_1:1;
    end;
    suppose
      x in Vg;
      then ex k st x = k & k in dom g & 1 <= k & k <= n & g.k <> -1;
      hence thesis by A7,FINSEQ_1:1;
    end;
  end;
A12: len f=mi by A1;
  VG c= Ug \/ Vg
  proof
    let x be object;
    assume
A13: x in VG;
    then reconsider j=x as Element of NAT;
A14: 1 <= j by A7,A13,FINSEQ_1:1;
A15: j <= n by A7,A13,FINSEQ_1:1;
    n < mi by Lm7;
    then j < mi by A15,XXREAL_0:2;
    then j in dom f by A12,A14,FINSEQ_3:25;
    then
A16: j in dom g by A9,Th41;
    per cases;
    suppose
      g.j=-1;
      then j in {k: k in dom g & 1 <= k & k <= n & g.k = -1} by A14,A15,A16;
      hence thesis by XBOOLE_0:def 3;
    end;
    suppose
      g.j<>-1;
      then
      j in {k: k in dom g & 1 <= k & k <= n & g.k <> -1} by A14,A15,A16;
      hence thesis by XBOOLE_0:def 3;
    end;
  end;
  hence
A17: the carrier of G = Ug \/ Vg by A10,XBOOLE_0:def 10;
  defpred P[Nat] means
$1 <= cn implies (for v3,j st v3<>v1 & v3=j
  & RM.$1.f.(n+j)<>-1 holds ex p,P st p is_simple_vertex_seq_at RM.$1.f,j,n & (
  for m st 1<=m & m<len p holds p.m in UsedVx(RM.$1.f,n)) & P
  is_oriented_edge_seq_of p & P is_shortestpath_of v1,v3,UsedVx(RM.$1.f,n),W &
  cost(P,W)=RM.$1.f.(2*n+j) & (not v3 in UsedVx(RM.$1.f,n) implies P
islongestInShortestpath UsedVx(RM.$1.f,n),v1,W )) & (for m,j st RM.$1.f.(n+j) =
-1 & 1<=j & j<=n & m in UsedVx(RM.$1.f,n) holds f.(2*n+n*m+j) = -1) & (for m st
  m in UsedVx(RM.$1.f,n) holds RM.$1.f.(n+m) <> -1);
  1 <= mi by NAT_1:12;
  then
A18: 1 in dom f by A12,FINSEQ_3:25;
A19: ( for m st 1<=m & m<=n holds f.m=1)& for m st 2<=m & m<=n holds f.(n+m)
  =-1 by A1;
  then {1} = UsedVx(RM.1.f,n) by A5,A8,A18,Th47;
  then
A20: 1 in UsedVx(RM.1.f,n) by TARSKI:def 1;
A21: for k st P[k] holds P[k+1]
  proof
    let k;
    assume
A22: P[k];
    now
      set FK1=RM.(k+1).f, UV1=UsedVx(FK1,n);
      set FK=RM.k.f;
      assume
A23:  k+1 <= cn;
      then
A24:  k < cn by NAT_1:13;
      then
A25:  OuterVx(FK,n) <> {} by Def4;
      per cases;
      suppose
        k=0;
        hence (for v3,j st v3<>v1 & v3=j & FK1.(n+j)<>-1 holds ex p,P st p
is_simple_vertex_seq_at FK1,j,n & (for m st 1<=m & m<len p holds p.m in UV1) &
P is_oriented_edge_seq_of p & P is_shortestpath_of v1,v3,UV1,W & cost(P,W)=FK1.
(2*n+j) & (not v3 in UV1 implies P islongestInShortestpath UV1,v1,W )) & (for m
,j st FK1.(n+j) = -1 & 1<=j & j<=n & m in UV1 holds f.(2*n+n*m+j) = -1) & for m
        st m in UV1 holds FK1.(n+m) <> -1 by A1,A2,A5,Lm15;
      end;
      suppose
        k<>0;
        then k >= 1+0 by INT_1:7;
        then 1 in UsedVx(FK,n) by A20,A24,Th48;
        hence (for v3,j st v3<>v1 & v3=j & FK1.(n+j)<>-1 holds ex p,P st p
is_simple_vertex_seq_at FK1,j,n & (for m st 1<=m & m<len p holds p.m in UV1) &
P is_oriented_edge_seq_of p & P is_shortestpath_of v1,v3,UV1,W & cost(P,W)=FK1.
(2*n+j) & (not v3 in UV1 implies P islongestInShortestpath UV1,v1,W )) & (for m
,j st FK1.(n+j) = -1 & 1<=j & j<=n & m in UV1 holds f.(2*n+n*m+j) = -1) & for m
st m in UV1 holds FK1.(n+m) <> -1 by A1,A2,A5,A22,A23,A25,Lm20,NAT_1:13;
      end;
    end;
    hence thesis;
  end;
A26: RM.0 .f = f by Th21;
A27: P[0]
  proof
    set UV=UsedVx(RM.0 .f,n), h=RM.0 .f;
    assume 0 <= cn;
    hereby
      let v3,j;
      assume that
A28:  v3<>v1 and
A29:  v3=j and
A30:  h.(n+j)<>-1;
A31:  v3 in VG;
      then 1<=j by A7,A29,FINSEQ_1:1;
      then 1 < j by A2,A28,A29,XXREAL_0:1;
      then
A32:  1+1 <= j by INT_1:7;
      assume
      not (ex p,P st p is_simple_vertex_seq_at h,j,n & (for m st 1<=m & m<
len p holds p.m in UV) & P is_oriented_edge_seq_of p & P is_shortestpath_of v1,
v3,UV,W & cost(P,W)=h.(2*n+j) & (not v3 in UV implies P islongestInShortestpath
      UV,v1,W));
      j<=n by A7,A29,A31,FINSEQ_1:1;
      hence contradiction by A1,A26,A30,A32;
    end;
    thus for m,j st h.(n+j) = -1 & 1<=j & j<=n & m in UV & not f.(2*n+n*m+j) =
    -1 holds contradiction by A5,A26,A8,A19,A18,Th47;
    let m;
    assume
A33: m in UsedVx(h,n);
    assume h.(n+m) = -1;
    thus contradiction by A5,A26,A8,A19,A18,A33,Th47;
  end;
A34: for k holds P[k] from NAT_1:sch 2(A27,A21);
  ex ii being Nat st ii<=n & OuterVx(RM.ii.f,n) = {} by Th40;
  then
A35: OuterVx(g,n) = {} by A9,Def4;
A36: now
    let v3,v4;
    assume that
A37: v3 in Ug and
A38: v4 in Vg;
    v3 in VG;
    then reconsider m=v3 as Element of NAT;
    consider j such that
A39: v4 = j and
A40: j in dom g and
A41: 1 <= j & j <= n and
A42: g.j <> -1 by A38;
    now
      assume g.(n+j) <> -1;
      then j in {k: k in dom g & 1 <= k & k <= n & g.k <> -1 & g.(n+k) <> -1}
      by A40,A41,A42;
      hence contradiction by A35;
    end;
    then -1=f.(2*n+n*m+j) by A9,A34,A37,A41
      .=Weight(v3,v4,W) by A1,A39;
    hence not ex e st e in the carrier' of G & e orientedly_joins v3,v4 by Th23
;
  end;
A43: f.1=1 by A1,A5;
  now
    assume
A44: cn=0;
    1 in {k: k in dom f & 1 <= k & k <= n & f.k <> -1 & f.(n+k) <> -1} by A5
,A43,A8,A18;
    hence contradiction by A9,A26,A35,A44;
  end;
  then cn >= 1+0 by INT_1:7;
  then
A45: v1 in Ug by A2,A9,A20,Th48;
  hereby
    assume v2 in Ug;
    then g.(n+i) <> -1 by A4,A9,A34;
    then consider p,P such that
A46: p is_simple_vertex_seq_at g,i,n and
    for m st 1<=m & m<len p holds p.m in Ug and
A47: P is_oriented_edge_seq_of p and
A48: P is_shortestpath_of v1,v2,Ug,W and
A49: cost(P,W)=g.(2*n+i) and
    not v2 in Ug implies P islongestInShortestpath Ug,v1,W by A2,A3,A4,A9,A34;
    take p,P;
    thus p is_simple_vertex_seq_at g,i,n by A46;
    thus P is_oriented_edge_seq_of p by A47;
    thus P is_shortestpath_of v1,v2,W by A17,A36,A45,A48,Th16;
    thus cost(P,W)=g.(2*n+i) by A49;
  end;
  thus  thesis by A17,A36,A45,Th11;
end;
