#include <bits/stdc++.h>
using namespace std;
int countbit(int n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); }
int lowbit(int n) { return (n ^ (n - 1)) & n; }
const double pi = acos(-1.0);
const double eps = 1e-7;
template <class T>
T sqr(T x) {
  return x * x;
}
int N, M, K;
int p[5001], h[5001];
int path[5001];
int getRoot(int x) {
  if (p[x] == x) return x;
  return p[x] = getRoot(p[x]);
}
void unite(int x, int y) {
  int px = getRoot(x), py = getRoot(y);
  if (px == py) return;
  int hx = h[px], hy = h[py];
  if (hx > hy)
    p[py] = px;
  else if (hx < hy)
    p[px] = py;
  else
    p[px] = py, h[py]++;
}
struct Edge {
  int u, v;
  double w;
  int index;
  bool operator<(const Edge &obj) const { return w < obj.w; }
};
vector<Edge> e1, e2, e3, e;
int check(double x) {
  e3.clear();
  for (int _n = e1.size(), i = 0; i < _n; ++i) {
    Edge te = e1[i];
    te.w += x;
    e3.push_back(te);
  }
  e = e2;
  for (int _n = e1.size(), i = 0; i < _n; ++i) e.push_back(e3[i]);
  sort(e.begin(), e.end());
  int index = 0;
  for (int _n = N, i = 0; i < _n; ++i) h[i] = 1, p[i] = i;
  int ret = 0;
  for (int _n = M, i = 0; i < _n; ++i) {
    int u = e[i].u, v = e[i].v;
    int pu = getRoot(u), pv = getRoot(v);
    if (pu == pv) continue;
    unite(u, v);
    path[index++] = e[i].index;
    if (u == 0 || v == 0) ++ret;
    if (index == N - 1) break;
  }
  return ret;
}
int main() {
  scanf("%d %d %d", &N, &M, &K);
  e1.clear();
  e2.clear();
  for (int _n = M, i = 0; i < _n; ++i) {
    Edge te;
    scanf("%d %d %lf", &te.u, &te.v, &te.w);
    te.u--, te.v--, te.index = i + 1;
    if (te.u == 0 || te.v == 0)
      e1.push_back(te);
    else
      e2.push_back(te);
  }
  if (K == 0 && N != 1) {
    printf("-1\n");
    return 0;
  }
  for (int _n = e1.size(), i = 0; i < _n; ++i) e1[i].w += eps * i;
  double l = -100000, r = 100000, mid;
  while (r - l > eps) {
    mid = (l + r) / 2;
    if (check(mid) > K)
      l = mid;
    else
      r = mid;
  }
  if (check(l) != K) check(r);
  printf("%d\n", N - 1);
  for (int _n = N - 1, i = 0; i < _n; ++i) {
    if (i) printf(" ");
    printf("%d", path[i]);
  }
  printf("\n");
  return 0;
}
