Pagini recente » Cod sursa (job #1237563) | Cod sursa (job #2385889) | Cod sursa (job #1378323) | Cod sursa (job #2982362) | Cod sursa (job #764917)
Cod sursa(job #764917)
Program lazy;
type tip=record
x,y:int64;
c,c2:int64;
pos:longint;
end;
var a:array [0..200005] of tip;
n,m,i,k,x,y,poz,lev:longint;
b1,b2:array [1..1 shl 17] of integer;
tata,indice:array [0..200005] of longint;
s:string;
fi,fo:text;
procedure sort(l,r:longint);
var i,j,y:longint;
k,k2:int64;
begin
i:=l; j:=r; k:=a[indice[(l+r) div 2]].c; k2:=a[indice[(l+r) div 2]].c2;
repeat
while (a[indice[i]].c<k) or ((a[indice[i]].c=k) and (a[indice[i]].c2>k2) and (i<=r)) do inc(i);
while (a[indice[j]].c>k) or ((a[indice[j]].c=k) and (a[indice[j]].c2<k2) and (j>=l)) do dec(j);
if i<=j then begin
y:=indice[i]; indice[i]:=indice[j]; indice[j]:=y;
inc(i); dec(j);
end;
until i>=j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
function radacina(nod:longint):longint;
var aux,r:longint;
begin
aux:=nod; r:=nod;
while tata[r]<>r do r:=tata[r];
radacina:=r;
while tata[nod]<>nod do begin aux:=tata[nod]; tata[nod]:=r; nod:=aux; end;
end;
procedure scoate(var val:int64);
var aux:int64;
begin
aux:=1; val:=0;
while s[lev]<>' ' do begin
if s[i]='-' then val:=-val else val:=val+(ord(s[lev])-48)*aux;
aux:=aux*10;
dec(lev);
end;
dec(lev);
end;
begin
assign(fi,'lazy.in');
assign(fo,'lazy.out');
settextbuf(fi,b1); settextbuf(fo,b2);
reset(fi); rewrite(fo); readln(fi,n,m);
for i:=1 to m do begin
readln(fi,s); s:=' '+s; lev:=length(s);
scoate(a[i].c2); scoate(a[i].c); scoate(a[i].y); scoate(a[i].x);
a[i].pos:=i; indice[i]:=i;
end;
sort(1,m);
for i:=1 to n do tata[i]:=i;
i:=1; k:=n-1;
while k>0 do begin
poz:=indice[i];
x:=radacina(a[poz].x); y:=radacina(a[poz].y);
if x<>y then begin dec(k); writeln(fo,a[poz].pos); tata[x]:=y; end;
inc(i);
end;
close(fo);
end.