#include <bits/stdc++.h>
using namespace std;
template <typename G, typename H>
struct triple {
  G first, second;
  H T;
  triple(G x, G y, H z) : first(x), second(y), T(z) {}
  triple() : first(0), second(0), T(0) {}
};
struct DS {
  vector<int> parent, cont;
  DS(int n) {
    parent = vector<int>(n);
    cont = vector<int>(n, 1);
    for (int i = 0; i < n; i++) parent[i] = i;
  }
  int SetOf(int x) {
    return parent[x] = (parent[x] == x ? x : SetOf(parent[x]));
  }
  bool Merge(int x, int y) {
    x = SetOf(x);
    y = SetOf(y);
    if (x == y) return false;
    if (cont[x] > cont[y]) swap(x, y);
    cont[y] += cont[x];
    parent[x] = y;
    return true;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  int deg = 0;
  map<pair<int, int>, int> mp;
  vector<triple<int, long double> > edges;
  for (int i = 0; i < m; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    --x;
    --y;
    if (x > y) swap(x, y);
    mp[{x, y}] = i + 1;
    edges.push_back({x, y, (long double)w});
    deg += (x == 0);
  }
  if (deg < k) {
    cout << "-1\n";
    return 0;
  }
  vector<int> ed;
  auto val = [&](long double x) {
    for (auto &i : edges)
      if (i.first == 0) i.T += x;
    ed.clear();
    DS ds(n);
    sort(edges.begin(), edges.end(),
         [](triple<int, long double> x, triple<int, long double> y) {
           if (x.T == y.T) return x.first < y.first;
           return x.T < y.T;
         });
    int ret = 0;
    for (int i = 0; i < m; i++) {
      if (ds.SetOf(edges[i].first) != ds.SetOf(edges[i].second) &&
          (ret + (edges[i].first == 0) <= k)) {
        ds.Merge(edges[i].first, edges[i].second);
        ed.push_back(i);
        ret += (edges[i].first == 0);
      }
    }
    for (auto &i : edges)
      if (i.first == 0) i.T -= x;
    return ret;
  };
  long double l = -1e9, r = 1e9;
  for (int i = 0; i < 70; i++) {
    long double mid = (l + r) / 2;
    9999;
    if (val(mid) >= k)
      l = mid;
    else
      r = mid;
  }
  if (val(l) != k || ed.size() != n - 1)
    cout << "-1\n";
  else {
    cout << n - 1 << '\n';
    for (int i = 0; i < n - 1; i++) {
      int x = edges[ed[i]].first;
      int y = edges[ed[i]].second;
      cout << mp[{x, y}] << " \n"[i == n - 2];
    }
  }
  return 0;
}
