ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1389. Roadworks

I have #WA2 please help me!!!
Posted by Husan 27 Nov 2006 18:56
var
i,kol,n,m,k1,k2:integer;
reb,a:array[1..100,1..100]of integer;
ver:array[1..100]of integer;
procedure def_s(k1:integer);
var
i,j,n1,k:integer;
pr,q:array[1..100]of integer;
begin
for i:=1to n do pr[i]:=0;
i:=1;n1:=1;pr[k1]:=1;q[1]:=k1;

while(i<=n1)do begin
k:=q[i];
for j:=1to n do
if(a[k,j]>0)and (pr[j]=0)then begin
n1:=n1+1;
q[n1]:=j;
pr[j]:=k;
if (ver[k]=0) and (ver[j]=0) then begin ver[k]:=1;ver[j]:=1;kol:=kol+1;
reb[kol,1]:=k;reb[kol,2]:=j end;
end;
i:=i+1;
end;
end;

begin
readln(n,m);
for i:=1to m do begin
readln(k1,k2);
a[k1,k2]:=1;
a[k2,k1]:=1;
end;
def_s(1);
writeln(kol);
for i:=1to kol do writeln(reb[i,1],' ',reb[i,2]);
end.