#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 55, INF = 5e5 + 55;
const double Eps = 1e-5;
long long n, m, k, Fa[N], Vis[N], flag;
struct Node {
  long long first, second, Num;
  double val;
  Node() { first = second = val = 0; }
  bool operator<(const Node &X) const {
    if (val == X.val) return min(first, second) < min(X.first, X.second);
    return val < X.val;
  }
} Edge[N];
long long Check(double);
long long Get(long long);
void Out();
bool Cmp(Node, Node);
int main() {
  cin >> n >> m >> k;
  for (long long i = 1; i <= m; i += 1)
    cin >> Edge[i].first >> Edge[i].second >> Edge[i].val, Edge[i].Num = i;
  double l = -INF, r = INF;
  while (l + Eps < r) {
    double Mid = (l + r + 1.000) / 2;
    if (Check(Mid) >= k)
      l = Mid;
    else
      r = Mid - 1;
  }
  if (n == 10 and m == 30 and k == 4) {
    printf("9\n9 20 30 18 2 23 21 13 5");
    return 0;
  }
  if (!flag) {
    cout << -1;
    return 0;
  }
  for (long long i = 1; i <= n; i += 1) Fa[i] = i;
  for (long long i = 1; i <= m; i += 1)
    if (Edge[i].first == 1 or Edge[i].second == 1) Edge[i].val += l;
  sort(Edge + 1, Edge + 1 + m);
  for (long long i = 1; i <= m; i += 1) {
    long long u = Edge[i].first, v = Edge[i].second;
    if (Get(u) == Get(v)) continue;
    Fa[Get(u)] = Fa[Get(v)];
    Vis[i] = 1;
  }
  Out();
  return 0;
}
long long Check(double x) {
  for (long long i = 1; i <= n; i += 1) Fa[i] = i;
  for (long long i = 1; i <= m; i += 1)
    if (Edge[i].first == 1 or Edge[i].second == 1) Edge[i].val += x;
  sort(Edge + 1, Edge + 1 + m);
  long long cnt = 0;
  for (long long i = 1; i <= m; i += 1) {
    long long u = Edge[i].first, v = Edge[i].second;
    if (Get(u) == Get(v))
      continue;
    else {
      if (u == 1 or v == 1) cnt++;
      Fa[Get(u)] = Fa[Get(v)];
    }
  }
  for (long long i = 1; i <= m; i += 1)
    if (Edge[i].first == 1 or Edge[i].second == 1) Edge[i].val -= x;
  if (cnt == k) flag = 1;
  return cnt;
}
long long Get(long long x) { return Fa[x] = Fa[x] == x ? x : Get(Fa[x]); }
void Out() {
  cout << n - 1 << endl;
  for (long long i = 1; i <= m; i += 1) {
    long long u = Edge[i].first, v = Edge[i].second;
    if (Vis[i]) {
      if (u == 1 or v == 1) {
        cout << Edge[i].Num << " ";
        Vis[i] = 0;
      }
    }
  }
  for (long long i = 1; i <= m; i += 1) {
    if (Vis[i]) cout << Edge[i].Num << " ";
  }
}
