#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << "\t";
    return *this;
  }
} dbg;
template <class T>
void setmax(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
T Abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T Mod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
string toString(T n) {
  ostringstream oss;
  oss << n;
  oss.flush();
  return oss.str();
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
bool isVowel(char ch) {
  ch = tolower(ch);
  if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
    return true;
  return false;
}
bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
bool isLower(char c) { return c >= 'a' && c <= 'z'; }
long long Pow(long long B, long long P) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) R = (R * B);
    P /= 2;
    B = (B * B);
  }
  return R;
}
int BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return (int)R;
}
void binprint(long long mask, long long n) {
  long long i;
  string s = "";
  do {
    s += (mask % 2 + '0');
    mask /= 2;
  } while (mask);
  reverse(s.begin(), s.end());
  s = string(max(n - (int)s.size(), 0LL), '0') + s;
  for (i = (int)s.size() - n; i < (int)s.size(); i++) printf("%c", s[i]);
  printf("\n");
}
void ASCII_Chart() {
  int i, j, k;
  printf("ASCII Chart:(30-129)\n");
  for (i = 30; i < 50; i++) {
    for (j = 0; j < 5; j++) {
      k = i + j * 20;
      printf("%3d---> '%c'   ", k, k);
    }
    printf("\n");
  }
}
struct edges {
  int u, v, ind;
  double w;
  edges(int _u = 0, int _v = 0, double _w = 0, int _ind = 0) {
    u = _u;
    v = _v;
    w = _w;
    ind = _ind;
  }
};
vector<edges> e, e1, e2;
int N, M, p[5050], cnt, K;
bool comp(edges p, edges q) { return p.w < q.w; }
void precalc() {
  e1.clear();
  e2.clear();
  for (int i = 0; i < M; i++) {
    if (e[i].u == 0 || e[i].v == 0)
      e1.push_back(e[i]);
    else
      e2.push_back(e[i]);
  }
  sort(e1.begin(), e1.end(), comp);
  sort(e2.begin(), e2.end(), comp);
}
void merge(vector<edges> e3) {
  e.clear();
  int i = 0, j = 0;
  while (i < e2.size() && j < e3.size()) {
    if (e2[i].w < e3[j].w)
      e.push_back(e2[i++]);
    else
      e.push_back(e3[j++]);
  }
  for (; i < e2.size(); i++) e.push_back(e2[i]);
  for (; j < e3.size(); j++) e.push_back(e3[j]);
  return;
}
int find_parent(int u) {
  if (u != p[u]) p[u] = find_parent(p[u]);
  return p[u];
}
void Union(int a, int b) { p[b] = a; }
int calc_k(double x) {
  int ret, i;
  vector<edges> e3;
  for (i = 0; i < e1.size(); i++) {
    e3.push_back(e1[i]);
    e3[i].w += x;
  }
  merge(e3);
  for (i = 0; i < N; i++) p[i] = i;
  cnt = ret = 0;
  for (i = 0; i < M; i++) {
    int a = find_parent(e[i].u);
    int b = find_parent(e[i].v);
    if (a != b) {
      e[i].ind = -e[i].ind;
      Union(a, b);
      if (e[i].u == 0 || e[i].v == 0) ret++;
      cnt++;
    }
  }
  return ret;
}
void solve() {
  precalc();
  double low = -10001000, high = 10001000;
  for (int i = 0; i < e1.size(); i++) e1[i].w += (i * 1e-7);
  while (fabs(low - high) > 1e-7) {
    double mid = (low + high) / 2;
    if (calc_k(mid) > K)
      low = mid;
    else
      high = mid;
  }
  if (calc_k(low) != K) (calc_k(high) == K);
  return;
}
int main() {
  int i, j, test, Case = 1, u, v, w;
  test = 1;
  while (test--) {
    scanf("%d %d %d", &N, &M, &K);
    e.clear();
    for (i = 0; i < M; i++) {
      scanf("%d %d %d", &u, &v, &w);
      e.push_back(edges(u - 1, v - 1, w, i + 1));
    }
    if (K == 0) {
      if (N <= 1)
        printf("0\n");
      else
        printf("-1\n");
      continue;
    }
    solve();
    printf("%d\n", N - 1);
    for (i = 0; i < M; i++)
      if (e[i].ind <= 0) {
        printf("%d ", -e[i].ind);
      }
    printf("\n");
  }
  return 0;
}
