-
Notifications
You must be signed in to change notification settings - Fork 0
/
GRAFAS2.PAS
65 lines (58 loc) · 1.29 KB
/
GRAFAS2.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ MK 2001 }
{ paieskos i ploti algoritmas }
program grafas;
var
f : text;
g : array [1 .. 100, 1 .. 100] of boolean;
eil, { nagrinejamu virs eile }
griz, { is kurios i kuria ateita }
ats : array [1 .. 100] of shortint; { atstumai tarp virsuniu }
pg1, pg2, ck, ck1,
ilg, { atstumas nuo pirmos virsunes iki nagrinejamos }
galv, uod, { pirma nagrinejama ir pirma laisva }
sk, { virsuniu skaicius }
v1, v2 : shortint; { pradine ir galine virsunes }
begin
assign (f, 'graf.dat');
reset (f);
readln (f, v1, v2);
sk := 0;
while not eof (f) do
begin
inc (sk);
readln (f, pg1, pg2);
g [pg1, pg2] := true;
g [pg2, pg1] := true
end;
close (F);
for ck := 1 to sk do
ats [ck] := -1;
ats [v1] := 0;
eil [1] := v1;
galv := 1;
uod := 2;
ilg := 0;
while (galv < uod) and (ats [v2] = -1) do
begin
inc (ilg);
for ck := galv to uod - 1 do
begin
for ck1 := 1 to sk do
if (g [ck, ck1]) and (ats [ck1] = -1) then
begin
eil [uod] := ck1;
inc (uod);
ats [ck1] := ilg;
griz [ck1] := ck;
end;
inc (galv);
end
end;
pg1 := v2;
while pg1 <> v1 do
begin
write (pg1, ' ');
pg1 := griz [pg1]
end;
writeln (pg1)
end.