#include <bits/stdc++.h>
using namespace std;
struct dataStruct {
  int x, y, w, d;
};
int nArray[5010];
bool boolArray[100010];
dataStruct g[2][100010];
void swap(dataStruct &str1, dataStruct &str2) {
  dataStruct tmp = str1;
  str1 = str2;
  str2 = tmp;
}
int getfather(int x) {
  if (nArray[x] != x) nArray[x] = getfather(nArray[x]);
  return nArray[x];
}
void fin(int l, int r, int d) {
  int i = l, j = r;
  dataStruct mid = g[d][(l + r) / 2];
  while (i <= j) {
    while (g[d][i].w < mid.w || (g[d][i].w == mid.w && g[d][i].d < mid.d)) i++;
    while (g[d][j].w > mid.w || (g[d][j].w == mid.w && g[d][j].d > mid.d)) j--;
    if (i <= j) {
      swap(g[d][i], g[d][j]);
      i++;
      j--;
    }
  }
  if (i < r) fin(i, r, d);
  if (l < j) fin(l, j, d);
}
bool check1(int k, int &m1, int &m2, int &n) {
  int x, y, i;
  if (m1 < k) return false;
  for (i = 1; i <= n; i++) nArray[i] = i;
  for (i = 1; i <= m2; i++) {
    x = getfather(g[1][i].x);
    y = getfather(g[1][i].y);
    if (x != y)
      if (x < y)
        nArray[y] = x;
      else
        nArray[x] = y;
  }
  memset(boolArray, false, sizeof(boolArray));
  x = 0;
  for (i = 2; i <= n; i++) {
    y = getfather(i);
    if (!boolArray[y]) {
      x++;
      boolArray[y] = true;
    }
  }
  if (x > k) return false;
  for (i = 1; i <= m1; i++) {
    x = getfather(g[0][i].x);
    y = getfather(g[0][i].y);
    if (x != y) {
      if (x < y)
        nArray[y] = x;
      else
        nArray[x] = y;
    }
  }
  for (i = 1; i <= n; i++) {
    if (getfather(i) != 1) return false;
    return true;
  }
}
int check2(double delta, int k, int &n, int &m1, int &m2) {
  int i, j, s = 0, x, y, sum = 0;
  dataStruct t;
  bool c;
  for (i = 1; i <= n; i++) nArray[i] = i;
  memset(boolArray, false, sizeof(boolArray));
  i = 1;
  j = 1;
  while (s < n - 1) {
    if (i <= m1 && (g[0][i].w + delta < g[1][j].w ||
                    (g[0][i].w + delta <= g[1][j].w && sum < k) || j > m2)) {
      t = g[0][i];
      i++;
      c = true;
    } else {
      t = g[1][j];
      j++;
      c = false;
    }
    x = getfather(t.x);
    y = getfather(t.y);
    if (x != y) {
      nArray[y] = x;
      s++;
      if (c) sum++;
      boolArray[t.d] = true;
    }
  }
  return (sum);
}
int main() {
  int m, k, i, x, y, w, n, m1 = 0, m2 = 0;
  double l, r, mid;
  cin >> n >> m >> k;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> w;
    if (x == 1 || y == 1) {
      m1++;
      g[0][m1].x = x;
      g[0][m1].y = y;
      g[0][m1].w = w;
      g[0][m1].d = i;
    } else {
      m2++;
      g[1][m2].x = x;
      g[1][m2].y = y;
      g[1][m2].w = w;
      g[1][m2].d = i;
    }
  }
  if (!check1(k, m1, m2, n)) {
    cout << "-1";
    return 0;
  }
  fin(1, m1, 0);
  fin(1, m2, 1);
  l = -100000;
  r = 100000;
  while (true) {
    mid = (l + r) / 2;
    int temp = check2(mid, k, n, m1, m2);
    if (temp == k) {
      cout << n - 1 << endl;
      for (i = 1; i <= m; i++) {
        if (boolArray[i]) cout << i << " ";
      }
      return 0;
    } else if (temp < k)
      r = mid;
    else
      l = mid;
  }
  cout << "-1";
  return 0;
}
