#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, w, ind;
} a[200010], b[200010];
int fa[200010], ksj, ss, tt, ind[200010], n, m, k, mx;
inline int read() {
  char c = getchar();
  int x = 0, flag = 1;
  while (!isdigit(c)) {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * flag;
}
bool cmp(node a, node b) { return a.w < b.w; }
int find(int x) {
  int y = x;
  while (y != fa[y]) y = fa[y];
  while (x != y) {
    int tmp = fa[x];
    fa[x] = y;
    x = tmp;
  }
  return y;
}
int check(int mid) {
  for (int i = 1; i <= n; i++) fa[i] = i;
  int i = 1, j = 1, cnt = 0, t, x, y;
  while (i <= ss && j <= tt) {
    if (a[i].w + mid <= b[j].w)
      x = find(a[i].u), y = find(a[i].v), i++, t = 1;
    else
      x = find(b[j].u), y = find(b[j].v), j++, t = 0;
    if (x != y) fa[x] = y, cnt += t;
  }
  for (; i <= ss; i++) {
    x = find(a[i].u), y = find(a[i].v);
    if (x != y) fa[x] = y, cnt++;
  }
  return cnt;
}
int main() {
  n = read(), m = read(), k = read(), mx = 0;
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read(), w = read();
    if (u == 1 || v == 1)
      a[++ss] = node{u, v, w, i};
    else
      b[++tt] = node{u, v, w, i};
    mx = max(mx, w);
  }
  sort(a + 1, a + ss + 1, cmp);
  sort(b + 1, b + tt + 1, cmp);
  int l = -mx, r = mx, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid) >= k)
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  int mid = ans;
  for (int i = 1; i <= n; i++) fa[i] = i;
  int i = 1, j = 1, cnt = 0, t, x, y, tot = 0, w, id;
  while (i <= ss && j <= tt) {
    if (a[i].w + mid <= b[j].w && cnt < k)
      x = find(a[i].u), y = find(a[i].v), t = 1, id = a[i].ind, i++;
    else
      x = find(b[j].u), y = find(b[j].v), t = 0, id = b[j].ind, j++;
    if (x != y) fa[x] = y, cnt += t, tot++, ind[++ksj] = id;
  }
  for (; i <= ss && cnt < k; i++) {
    x = find(a[i].u), y = find(a[i].v);
    if (x != y) fa[x] = y, cnt++, tot++, ind[++ksj] = a[i].ind;
  }
  for (; j <= tt; j++) {
    x = find(b[j].u), y = find(b[j].v);
    if (x != y) fa[x] = y, tot++, ind[++ksj] = b[j].ind;
  }
  if (tot != n - 1 || cnt != k) {
    puts("-1");
    return 0;
  }
  cout << n - 1 << '\n';
  for (int i = 1; i < n; i++) cout << ind[i] << ' ';
  return 0;
}
