{$APPTYPE CONSOLE}
{$r-,q-,r-,i-,o+}
var
  pred,rank,a,b,c,nom:array [1..400000] of longint;
  n,m,k,i,ko:longint;

  function fs(x:longint):longint;
    begin
      if x<>pred[x]
        then pred[x]:=fs(pred[x]);
      fs:=pred[x];
    end;

  procedure union(x,y:longint);
    begin
      if rank[x]>rank[y]
        then pred[y]:=x
        else begin
               pred[x]:=y;
               if rank[x]=rank[y]
                 then inc(rank[y]);
             end;
    end;

begin
  assign(input,'roads.in'); reset(input);
  assign(output,'roads.out'); rewrite(output);
  readln(n,m,k);
  for i:=1 to n do
    begin
      pred[i]:=i;
      rank[i]:=0;
    end;
  for i:=1 to m do
    begin
      readln(a[i],b[i],c[i]);
      nom[i]:=0;
    end;
  ko:=0;
  for i:=1 to m do
    if (c[i]=1) and (k>0) and (fs(a[i])<>fs(b[i])) and (ko+1<=n-1)
      then begin
             dec(k);
             inc(ko);
             union(fs(a[i]),fs(b[i]));
             nom[i]:=1;
           end;
  for i:=1 to m do
    if (c[i]=0) and (fs(a[i])<>fs(b[i])) and (ko+1<=n-1)
      then begin
             inc(ko);
             union(fs(a[i]),fs(b[i]));
             nom[i]:=1;
           end;
  if (k>0) or (ko<>n-1)
    then writeln(-1)
    else for i:=1 to m do
           if nom[i]=1 then write(i,' ');
  close(input);
  close(output);
end. 
