#include <bits/stdc++.h>
using namespace std;
const int N = 5005, M = 1e5 + 7;
const double eps = 1e-5;
int n, m, k, s, cnt;
int tag[N], fa[N], ans[N];
struct edge {
  int u, t, id;
  double w;
  bool operator<(edge a) const { return w == a.w ? u > a.u : w < a.w; }
} e[M];
double fabs(double x) { return x < 0 ? -x : x; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int check(double x, int p) {
  for (int i = 1; i <= m; i++)
    if (e[i].u == 1) e[i].w += x;
  sort(e + 1, e + m + 1);
  int num = n, res = 0;
  cnt = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int u = find(e[i].u), t = find(e[i].t);
    if (u == t) continue;
    if (e[i].u == 1 && res == k && p) continue;
    fa[u] = t;
    ans[++cnt] = e[i].id;
    num--;
    res += (e[i].u == 1);
    if (num == 1) break;
  }
  for (int i = 1; i <= m; i++)
    if (e[i].u == 1) e[i].w -= x;
  return res;
}
int main() {
  int s = 0;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%lf", &e[i].u, &e[i].t, &e[i].w);
    if (e[i].u > e[i].t) swap(e[i].u, e[i].t);
    e[i].id = i;
    if (e[i].u == 1) s++;
  }
  if (s < k || (n > 1 && k == 0) || m < n - 1) return puts("-1"), 0;
  double l = -100000, r = 100000, mid;
  while (r - l > eps) {
    mid = (l + r) / 2.0;
    int v = check(mid, 0);
    if (v < k)
      r = mid - 1;
    else if (fabs(l - mid) < eps)
      break;
    else
      l = mid;
  }
  check(l, 1);
  printf("%d\n", n - 1);
  for (int i = 1; i < n; i++) printf("%d ", ans[i]);
}
