Pagini recente » Cod sursa (job #2372070) | Cod sursa (job #827359) | Cod sursa (job #923876) | Cod sursa (job #722613) | Cod sursa (job #764892)
Cod sursa(job #764892)
Program lazy;
type tip=record
x,y,pos:longint;
c,p:int64;
end;
var a:array [1..200001] of tip;
n,m,i,c2,k,x,y:longint;
tata:array [1..200001] of longint;
fi,fo:text;
procedure sort(l,r:longint);
var i,j:longint;
k,k2:int64;
y:tip;
begin
i:=l; j:=r; k:=a[(l+r) div 2].c; k2:=a[(l+r) div 2].p;
repeat
while (a[i].c<k) or ((a[i].c=k) and (a[i].p>k2) and (i<=r)) do inc(i);
while (a[j].c>k) or ((a[j].c=k) and (a[j].p<k2) and (j>=l)) do dec(j);
if i<=j then begin
y:=a[i]; a[i]:=a[j]; a[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;
begin
assign(fi,'lazy.in');
assign(fo,'lazy.out');
reset(fi); rewrite(fo); readln(fi,n,m);
for i:=1 to m do begin
readln(fi,a[i].x,a[i].y,a[i].c,c2);
a[i].p:=a[i].c*c2; a[i].pos:=i;
end;
sort(1,m);
for i:=1 to n do tata[i]:=i;
i:=1; k:=n-1;
while k>0 do begin
x:=radacina(a[i].x); y:=radacina(a[i].y);
if x<>y then begin dec(k); writeln(fo,a[i].pos); tata[x]:=y; end;
inc(i);
end;
close(fo);
end.