#include <bits/stdc++.h>
const int MaxN = 5e3 + 10, MaxM = 1e5 + 10, inf = 0x3f3f3f3f;
namespace IO {
char buf[1 << 15], *fs, *ft;
inline char getc() {
  return ft == fs && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), ft == fs)
             ? 0
             : *fs++;
}
template <typename T>
inline void read(T &x) {
  x = 0;
  T f = 1, ch = getchar();
  while (!isdigit(ch) && ch ^ '-') ch = getchar();
  if (ch == '-') f = -1, ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x *= f;
}
template <typename T, typename... Args>
inline void read(T &x, Args &...args) {
  read(x);
  read(args...);
}
char Out[1 << 24], *fe = Out;
inline void flush() {
  fwrite(Out, 1, fe - Out, stdout);
  fe = Out;
}
template <typename T>
inline void write(T x, char str) {
  if (!x) *fe++ = 48;
  if (x < 0) *fe++ = '-', x = -x;
  T num = 0, ch[20];
  while (x) ch[++num] = x % 10 + 48, x /= 10;
  while (num) *fe++ = ch[num--];
  *fe++ = str;
}
}  // namespace IO
using IO::read;
using IO::write;
template <typename T>
inline bool chkMin(T &a, const T &b) {
  return a > b ? (a = b, true) : false;
}
template <typename T>
inline bool chkMax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}
template <typename T>
inline T min(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
inline T max(T a, T b) {
  return a > b ? a : b;
}
struct Orz {
  int x, y, z, id;
  inline Orz(int x = 0, int y = 0, int z = 0, int id = 0)
      : x(x), y(y), z(z), id(id) {}
  inline bool operator<(const Orz &a) const {
    return z < a.z || (z == a.z && x > a.x);
  }
} e[MaxN];
int n, m, K, tot, fa[MaxN];
inline int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
std::vector<int> g;
inline int Kruskal(int mid) {
  for (int i = 1; i <= m; ++i)
    if (e[i].x == 1) e[i].z += mid;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  int cnt = 0;
  g.clear();
  std::sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; ++i) {
    int x = get(e[i].x), y = get(e[i].y);
    if (x == y) continue;
    fa[x] = y, g.push_back(e[i].id);
    if (e[i].x == 1) ++cnt;
  }
  for (int i = 1; i <= m; ++i)
    if (e[i].x == 1) e[i].z -= mid;
  return cnt;
}
inline void Clac(int mid) {
  for (int i = 1; i <= m; ++i)
    if (e[i].x == 1) e[i].z += mid;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  int cnt = 0, tot = 0;
  g.clear();
  std::sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; ++i) {
    int x = get(e[i].x), y = get(e[i].y);
    if (x == y) continue;
    if (e[i].x == 1 && cnt == K) continue;
    fa[x] = y, g.push_back(e[i].id);
    if (e[i].x == 1) ++cnt;
    ++tot;
  }
  if (cnt < K || tot != n - 1) {
    puts("-1");
    exit(0);
  }
}
int main() {
  read(n, m, K);
  for (int i = 1, x, y, z; i <= m; ++i) {
    read(x, y, z);
    if (x > y) std::swap(x, y);
    if (x == 1) ++tot;
    e[i] = Orz(x, y, z, i);
  }
  int l = -1e5, r = 1e5, ans = -inf;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (Kruskal(mid) < K)
      r = mid - 1;
    else
      l = mid + 1, ans = mid;
  }
  if (ans < -1e5)
    write(-1, '\n');
  else {
    Clac(r);
    write(n - 1, '\n');
    for (int i = 0; i < n - 1; ++i) write(g[i], ' ');
  }
  IO::flush();
  return 0;
}
