#include <bits/stdc++.h>
using namespace std;
struct E {
  int u, v, id;
  long long w;
} e[300010];
int g[5010];
int a[5010];
int n, m, p, t, sos, cnt;
double mid;
int find(int x) { return g[x] == x ? x : g[x] = find(g[x]); }
bool cmp(E x, E y) {
  return (x.w + (x.u == 1) * mid) < (y.w + (y.u == 1) * mid);
}
void kruskal(bool flag) {
  sos = 0;
  for (int i = 1; i <= n; i++) {
    g[i] = i;
  }
  cnt = 0;
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    if (sos == n - 1) return;
    int x = find(e[i].u);
    int y = find(e[i].v);
    if ((x != y) && (flag || (cnt + (e[i].u == 1) <= t))) {
      g[x] = y;
      a[++sos] = e[i].id;
      if (e[i].u == 1) cnt++;
    }
  }
  return;
}
int main() {
  scanf("%d%d%d", &n, &m, &t);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    e[i].id = i;
    if (e[i].u > e[i].v) swap(e[i].u, e[i].v);
    if (e[i].u == 1) ans++;
  }
  if (ans < t || m < n - 1 || (n > 1 && t == 0)) {
    printf("-1\n");
    return 0;
  }
  double l = -100000.0, r = 100000.0;
  while (r - l > 1e-5) {
    mid = (l + r) / 2.0;
    kruskal(1);
    if (cnt < t)
      r = mid;
    else if (cnt > t)
      l = mid;
    else
      break;
  }
  kruskal(0);
  if (cnt != t) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", n - 1);
  for (int i = 1; i <= sos; i++) {
    printf("%d ", a[i]);
  }
  return 0;
}
