NUM.ONE——PRIM
var a:array[1..1000,1..1000]of longint;
i,j,k,l,m,n,p,min,minp,minp2,num:longint;
v:array[1..1000]of boolean;
d:array[1..1000]of longint;
begin
readln(n);
for i:=1 to n do
for j:=1 to n do
begin
read(a[i,j]);
if a[i,j]=0 then
a[i,j]:=maxlongint;
end;
fillchar(v,sizeof(v),true);
d[1]:=1;
v[1]:=false;
num:=1;
for p:=1 to n-1 do
begin
min:=maxlongint;
for j:=1 to num do
for i:=1 to n do
if (a[d[j],i]<min)and(v[i]) then
begin
min:=a[d[j],i];
minp:=i;
minp2:=j;
end;
d[p+1]:=minp;
//writeln(minp,' ',minp2);
v[minp]:=false;
num:=num+1;
end;
for i:=1 to n do
write(d[i],' ');
end.