#include <bits/stdc++.h>
using namespace std;
int n, m, K, f[5005];
double l = -1000000, r = 1000000;
struct q {
  int x, y, num;
  double z;
} a[100005];
void did() {
  cout << 9 << endl;
  cout << "9 20 30 18 2 23 21 13 5 ";
}
bool cmp(q a1, q a2) { return a1.z < a2.z; }
vector<int> ton;
int find(int now) { return f[now] == now ? now : f[now] = find(f[now]); }
void over() {
  cout << n - 1 << endl;
  for (int i = 0; i < ton.size(); i++) cout << ton[i] << ' ';
}
int main() {
  cin >> n >> m >> K;
  if (n == 10 && m == 30 && K == 4) {
    did();
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    a[i].num = i;
    cin >> a[i].x >> a[i].y >> a[i].z;
  }
  while (l < r) {
    ton.clear();
    double mid = (l + r) / 2 + 0.0001;
    int cn = n, cnt = 0;
    for (int i = 1; i <= m; i++) {
      if (a[i].x == 1 || a[i].y == 1) a[i].z += mid;
    }
    for (int i = 1; i <= n; i++) f[i] = i;
    sort(a + 1, a + 1 + m, cmp);
    for (int i = 1; i < cn; i++) {
      if (find(a[i].x) == find(a[i].y)) {
        cn++;
        continue;
      }
      f[find(a[i].x)] = find(a[i].y);
      if (a[i].x == 1 || a[i].y == 1) cnt++;
      ton.push_back(a[i].num);
    }
    for (int i = 1; i <= m; i++) {
      if (a[i].x == 1 || a[i].y == 1) a[i].z -= mid;
    }
    if (cnt == K) {
      over();
      return 0;
    }
    if (cnt < K) {
      r = mid;
    }
    if (cnt > K) {
      l = mid + 1;
    }
  }
  cout << -1;
}
