#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000000, inv2 = (MOD + 1) / 2;
long double eps = 1e-6;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long double pi = acos(-1.0L);
struct node {
  int x, y, z, op, id;
} a[1000000 + 10], c[1000000 + 10];
bool cmp(node a, node b) {
  if (a.z != b.z) return a.z < b.z;
  return a.op < b.op;
}
int f[1000000 + 10], used[1000000 + 10], n, m, k;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '--') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
int dsu(int k) {
  if (f[k] != k) f[k] = dsu(f[k]);
  return f[k];
}
pair<int, long long> calc(int mid) {
  for (int i = (int)1; i <= (int)m; i++) {
    c[i] = a[i];
    if (c[i].op) c[i].z += mid;
  }
  sort(c + 1, c + m + 1, cmp);
  for (int i = (int)1; i <= (int)m; i++) used[i] = 0;
  for (int i = (int)1; i <= (int)n; i++) f[i] = i;
  int s = 0, num = n;
  long long ans = 0;
  for (int i = (int)1; i <= (int)m; i++) {
    int x = dsu(c[i].x), y = dsu(c[i].y);
    if (x != y && s + c[i].op <= k) {
      f[x] = y;
      ans += c[i].z;
      used[c[i].id] = 1;
      s += c[i].op;
      num--;
    }
  }
  if (num != 1) ans = 2e10;
  return make_pair(s, ans);
}
void solve() {
  pair<int, long long> t = calc(-2e5);
  if (t.second == 2e10 || t.first < k) {
    printf("-1\n");
    return;
  }
  t = calc(2e5);
  if (t.second < 2e10 && t.first > k) {
    printf("-1\n");
    return;
  }
  int l = -1e5, r = 1e5;
  int ans = -1e5;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (calc(mid).first >= k)
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  if (calc(ans).first > k) ans++, calc(ans);
  int res = 0;
  for (int i = (int)1; i <= (int)m; i++)
    if (used[i]) res++;
  printf("%d\n", res);
  for (int i = (int)1; i <= (int)m; i++)
    if (used[i]) printf("%d ", i);
}
int main() {
  n = read(), m = read(), k = read();
  for (int i = (int)1; i <= (int)m; i++) {
    a[i].x = read(), a[i].y = read(), a[i].z = read();
    if (a[i].x == 1 || a[i].y == 1) a[i].op = 1;
    a[i].id = i;
  }
  solve();
  return 0;
}
