{$n+} Uses Graph, Crt; Const nn = 50; Var N, main_n: Integer; Type TGraph = Array[1 .. nn, 1 .. nn] Of LongInt; Procedure Warshall(Var a: TGraph; c: TGraph); Var i, j, k: Integer; Begin For i := 1 To n Do For j := 1 To n Do a[i,j] := c[i,j]; For k := 1 To n Do For i := 1 To n Do For j := 1 To n Do If (a[i,k]+a[k,j] < a[i,j]) Then a[i,j] := a[i,k] + a[k,j] End; Procedure ReadFileGraph(Var a: TGraph); Var i,j: integer; filename: String; f: Text; Begin Write('Enter file name: '); ReadLn(filename); Write(' main N = '); ReadLn(main_N); Assign(f, filename); Reset(f); Readln(f,N); For i := 1 To n Do For j := 1 To n Do Read(f,a[i,j]); Close(f); End; Procedure ReadGraph(Var a: TGraph); Var i, j: Integer; Begin WriteLn('matriza smezhnosti'); Write('n = '); ReadLn(n); Write(' main N = '); ReadLn(main_N); For i := 1 To n Do For j := 1 To n Do Begin Write('G', i, ',', j, '= '); ReadLn(a[i,j]); End; WriteLn; End; (* Volvo stuff *) procedure Arrow(xs, ys, xf, yf: longint; color: byte); const delta_phi = 1; delta_len = 10; R2D = 180 / Pi; type polar = record phi, len: double; end; point = record x, y: longint; end; function sign(x: longint): longint; begin if x = 0 then sign := 1 else sign := x div abs(x); end; procedure polar_to_decart(var plr: polar; var pnt: point); begin pnt.x := xs + sign(xf - xs) * trunc(plr.len * cos(plr.phi/R2D)); pnt.y := ys + sign(yf - ys) * trunc(plr.len * sin(plr.phi/R2D)); end; var fn, p1_plr, p2_plr: polar; p1, p2: point; begin setcolor(color); line(xs, ys, xf, yf); if xs <> xf then begin fn.phi := arctan((ys - yf) / (xf - xs)) * R2D; fn.len := sqrt(sqr(1.0*xf - xs) + sqr(1.0*yf - ys)); p1_plr.phi := fn.phi + delta_phi; p1_plr.len := fn.len - delta_len; p2_plr.phi := fn.phi - delta_phi; p2_plr.len := fn.len - delta_len; polar_to_decart(p1_plr, p1); polar_to_decart(p2_plr, p2); line(p1.x, p1.y, xf, yf); line(p2.x, p2.y, xf, yf); end else begin line(xs - 2, yf - sign(yf - ys)*delta_len, xf, yf); line(xs + 2, yf - sign(yf - ys)*delta_len, xf, yf); end end; procedure ArrowLine(xs, ys, xf, yf: integer; positive: boolean; color:byte); begin if positive then Arrow(xs, ys, xf, yf, color) else Arrow(xf, yf, xs, ys, color); end; var a, c: TGraph; i, j, v: Integer; gd, gm: Integer; k_sqrt: Integer; outstr_: String; coord: Array[1 .. nn] Of Record xc, yc: LongInt End; Const x0 = 20; y0 = 20; size_: integer = 80; begin ReadFileGraph( c ); warshall(a,c); gd := Detect; InitGraph(gd, gm, ''); k_sqrt := round(sqrt(n)); i := 1; j := 1; For v := 1 To n Do Begin If (v <> main_n) and (a[v, main_n] = 10000) Then SetColor(Green) Else SetColor(Blue); If v = main_n Then SetColor(Red); Circle(x0+i*size_, y0+j*size_, 5); coord[v].xc := x0+i*size_; coord[v].yc := y0+j*size_; Str(v, outstr_); OutTextXY(x0+i*size_, y0+j*size_-10, outstr_); If i = k_sqrt Then Inc(j); If i < k_sqrt Then Inc(i) Else i := 1; End; For i := 1 To n Do For j := 1 To n Do Begin If (c[i,j] < 10000) and (i <> j) Then ArrowLine(coord[i].xc, coord[i].yc, coord[j].xc, coord[j].yc, True, White); End; ReadLn; CloseGraph; end.