#include <bits/stdc++.h>
using namespace std;
int p[5500];
int h[5500];
int n, m;
int k;
int root(int v) {
  if (v == p[v]) return v;
  return p[v] = root(p[v]);
}
void unite(int u, int v) {
  u = root(u);
  v = root(v);
  if (u == v) return;
  if (u != v) {
    if (h[u] < h[v])
      p[u] = v;
    else if (h[u] > h[v])
      p[v] = u;
    else {
      p[u] = v;
      ++h[v];
    }
  }
}
const double eps = 1e-7;
struct Edge {
  int u, v;
  int ind;
  double w;
  bool operator<(const Edge& e) const { return w < e.w; }
};
template <typename T>
void merge(const vector<T>& a, const vector<T>& b, vector<T>& c) {
  c.resize(0);
  int i = 0, j = 0;
  while (i < a.size() && j < b.size()) {
    if (a[i] < b[j]) {
      c.push_back(a[i]);
      ++i;
    } else {
      c.push_back(b[j]);
      ++j;
    }
  }
  for (; i < a.size(); ++i) c.push_back(a[i]);
  for (; j < b.size(); ++j) c.push_back(b[j]);
}
vector<Edge> e;
vector<Edge> e1, e2;
void precalc() {
  for (int i = 0; i < e.size(); ++i) {
    if (e[i].u == 0 || e[i].v == 0) {
      e1.push_back(e[i]);
    } else
      e2.push_back(e[i]);
  }
  sort(e2.begin(), e2.end());
  sort(e1.begin(), e1.end());
}
int test(double x) {
  vector<Edge> e3;
  for (int i = 0; i < e1.size(); ++i) {
    e3.push_back(e1[i]);
    e3[i].w += x;
  }
  merge(e2, e3, e);
  for (int i = 0; i < n; ++i) {
    h[i] = 1;
    p[i] = i;
  }
  int ret = 0;
  for (int i = 0; i < e.size(); ++i) {
    int u = e[i].u;
    int v = e[i].v;
    u = root(u);
    v = root(v);
    if (u != v) {
      e[i].ind = -e[i].ind;
      if (e[i].u == 0 || e[i].v == 0) ++ret;
      unite(u, v);
    }
  }
  return ret;
}
void solve() {
  precalc();
  for (int i = 0; i < e1.size(); ++i) {
    e1[i].w += eps * i;
  }
  double l = -10000000;
  double r = 10000000;
  while (l + eps < r) {
    double m = (l + r) / 2;
    if (test(m) > k)
      l = m;
    else
      r = m;
  }
  if (test(l) != k) test(r);
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  if (k == 0) {
    if (n > 1)
      printf("-1");
    else
      printf("0");
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    --u;
    --v;
    Edge ed;
    ed.u = u;
    ed.v = v;
    ed.ind = i + 1;
    ed.w = w;
    e.push_back(ed);
  }
  solve();
  printf("%d\n", n - 1);
  for (int i = 0; i < e.size(); ++i)
    if (e[i].ind < 0) {
      printf("%d ", -e[i].ind);
    }
  return 0;
}
