Nazdar, hľadal som všade ale nikde som nič nenašiel. Chyba je asi s maticou ale neviem aká. Hádže ju tak kde niečo idem zapísať do matice ( A[i,j] , A[c1,c2] ) .
program uloha2;
var m,n,p,i,c1,c2,j,k,u:longint; //n = gaštany, m = paličky
A:array [1..1000000, 1..1000001] of boolean;
const pocet = 1000001;
begin
read(n);
readln(m);
u:=n;
for i := 1 to n do begin
for j := 1 to n do begin
A[i,j]:=false;
end;
end;
for i:=1 to m do begin
read(c1);
readln(c2);
A[c1,c2]:=true;
A[c2,c1]:=true;
A[i,pocet]:=true;
end;
repeat
for i :=1 to n do begin
if A[i,pocet] = true then begin
for j:=1 to n do begin
if (A[i,j] = true) then begin
p:=0;
for k:=1 to n do begin
if (A[k,j] = true) then Inc(p);
end;
end;
end;
if p > 1 then begin
A[i,pocet]:= false;
u:=u-1;
end;
end;
end;
until (u=0);
end.