-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTILTAS.PAS
71 lines (65 loc) · 1.28 KB
/
TILTAS.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
66
67
68
69
70
71
{ MK 2002 }
{ XII Olimpiados 225 uzd PAZINTYS }
program tiltas;
{ rasti bent viena tilta }
type
TG = array [1 .. 200, 1 .. 200] of boolean;
Taib = set of 1 .. 200;
var
g : Tg;
ck, viso : integer;
procedure nuskaitymas (var viso : Integer; var G : Tg);
var
f : Text;
ckx, cky, pg, v : integer;
begin
assign (f, 'tiltas.dat');
reset (F);
readln (f, viso);
for cky := 1 to viso do
for ckx := 1 to viso do
g [ckx, cky] := false;
for ckx := 1 to viso do
begin
read (f, pg);
for cky := 1 to pg do
begin
read (f, v);
g [ckx, v] := true
end;
readln (f)
end;
close (F)
end;
procedure tikrink (virs, v : integer; var aib : Taib);
var
ck : Integer;
begin
if aib <> [1 .. viso] then
for ck := 1 to viso do
if (ck <> v) and not (ck in aib) and g [virs, ck]
then
begin
aib := aib + [ck];
tikrink (ck, v, aib)
end
end;
function jungus (v : integer) : boolean;
var
pg, aib : Taib;
begin
aib := [];
tikrink (v mod viso + 1, v, aib);
pg := [1 .. viso] - [v];
if aib = pg then jungus := true
else jungus := false
end;
begin
nuskaitymas (viso, g);
for ck := 1 to viso do
if not jungus (ck) then
begin
writeln (ck);
break
end
end.