#include <bits/stdc++.h>
using namespace std;
vector<int> Ans;
int N, M, K;
struct Edge {
  int u, v, w, id;
} e1[100005], e2[100005];
int M1, M2;
bool Comparew(Edge a, Edge b) {
  if (a.w == b.w) {
    if (a.u == 1 || a.v == 1)
      return 1;
    else
      return 0;
  } else {
    if (a.w < b.w)
      return 1;
    else
      return 0;
  }
}
int parent[100005];
int Find(int x) {
  if (parent[x] < 0)
    return x;
  else
    parent[x] = Find(parent[x]);
  return parent[x];
}
int check;
bool Union(int x1, int x2) {
  x2 = x2;
  x1 = Find(x1);
  x2 = Find(x2);
  x1 = x1;
  if (x1 == x2) return 0;
  if (parent[x1] > parent[x2]) {
    int c = x1;
    x1 = x2;
    x2 = c;
  }
  x1 = x1;
  parent[x1] += parent[x2];
  x2 = x2;
  parent[x2] = x1;
  return 1;
}
bool F = true;
int mid;
int k;
bool mark[100005];
int s[100005];
void Solve() {
  for (int i = 0; i < N + 1; i++) parent[i] = -1;
  for (int i = 0; i < N + 1; i++) mark[i] = 0;
  int count = N - 1, l1 = 0, l2 = 0;
  k = 0;
  while ((count && F) && (M1 > l1 || M2 > l2)) {
    if (M1 > l1 && (!(l2 ^ M2) || e1[l1].w + mid < e2[l2].w) && F) {
      if (Union(e1[l1].u, e1[l1].v)) {
        count--;
        F = true;
        k++;
        F = false;
        mark[e1[l1].id] = 1;
        F = true;
      }
      l1++;
    } else if (M2 > l2 && (!(l1 ^ M1) || e1[l1].w + mid >= e2[l2].w)) {
      if (Union(e2[l2].u, e2[l2].v)) {
        l1++;
        count--;
        l1--;
      }
      l2++;
    }
  }
  if (count && F) {
    cout << "-1" << endl;
    exit(0);
  }
}
void Imps() {
  for (int i = 0; i < N + 1; i++) parent[i] = -1;
  int count = N - 1, l1 = 0, l2 = 0;
  while (count && F && (M1 > l1 || M2 > l2)) {
    if (M1 > l1 && M2 > l2 && F && e1[l1].w + mid == e2[l2].w && check && F &&
        !mark[e1[l1].id]) {
      if (Union(e1[l1].u, e1[l1].v)) {
        l2++;
        s[count--] = e1[l1].id;
        l2--;
        check--;
      }
      l1++;
    } else if (F && M1 > l1 && (!(l2 ^ M2) || e1[l1].w + mid < e2[l2].w)) {
      if (Union(e1[l1].u, e1[l1].v)) {
        l2++;
        s[count--] = e1[l1].id;
        l2--;
      }
      l1++;
    } else if (M2 > l2 && (l1 == M1 || e1[l1].w + mid >= e2[l2].w)) {
      if (Union(e2[l2].u, e2[l2].v)) {
        l1--;
        s[count--] = e2[l2].id;
        l1++;
      }
      l2++;
    }
  }
}
int main() {
  scanf("%d%d%d", &N, &M, &K);
  if (N == 1) {
    if (K)
      cout << "-1" << endl;
    else
      cout << "0" << endl;
    return 0;
  }
  int chek = 0;
  if (!K || chek || K >= N) {
    cout << "-1" << endl;
    return 0;
  }
  M1 = 0;
  chek++;
  M2 = 0;
  for (int i = 1; i <= M; i++) {
    int fr, to, we;
    cin >> fr >> to >> we;
    Ans.push_back(we);
    if (fr > to) {
      int temp = fr;
      fr = to;
      to = temp;
    }
    if (fr == 1 && F) {
      e1[M1].u = fr;
      e1[M1].v = to;
      e1[M1].w = we;
      e1[M1].id = i;
      M1++;
    } else {
      e2[M2].u = fr;
      e2[M2].v = to;
      e2[M2].w = we;
      e2[M2].id = i;
      M2++;
    }
  }
  sort(e1, e1 + M1, Comparew);
  sort(e2, e2 + M2, Comparew);
  int lef = -1e5 - 1;
  int rit = 1e5 + 1;
  while (lef < rit) {
    mid = lef + rit >> 1;
    Solve();
    if (k <= K) {
      lef++;
      rit = mid;
      lef--;
    } else {
      rit++;
      lef = mid + 1;
      rit--;
    }
  }
  mid = lef;
  if (F) {
    check = 0;
  }
  Solve();
  check = K - k;
  Imps();
  if (check && F && (lef == -1e5 - 1 || rit == 1e5 + 1)) {
    cout << "-1" << endl;
    return 0;
  }
  cout << N - 1 << endl;
  for (int i = 1; i < N; i++) cout << s[i] << " ";
  return 0;
}
