#include <bits/stdc++.h>
const int maxn = 5e3 + 5, maxm = 1e5 + 5;
int n, m, k, slp, ans, vis[maxn], we, be;
struct Edge {
  int x, y, val, id;
  bool operator<(Edge b) const { return val < b.val; }
} w[maxm], b[maxm];
struct DSU {
  int fa[maxn];
  void clr() {
    for (int i = 1; i <= n; ++i) fa[i] = i;
  }
  int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
} dsu;
namespace wqs {
struct pair {
  int wcnt, vals;
  pair(int X = 0, int Y = 0) : wcnt(X), vals(Y){};
};
pair Kruskal(int V) {
  int wcnt = 0, vals = 0, fx, fy, i, j;
  dsu.clr();
  for (i = 1; i <= we; ++i) w[i].val += V;
  for (i = 1, j = 1;; ++i) {
    while (j <= we && w[j].val < b[i].val) {
      fx = dsu.getfa(w[j].x), fy = dsu.getfa(w[j].y);
      if (fx ^ fy) dsu.fa[fx] = fy, vals += w[j].val, ++wcnt;
      ++j;
    }
    if (i == be + 1) break;
    fx = dsu.getfa(b[i].x), fy = dsu.getfa(b[i].y);
    if (fx ^ fy) dsu.fa[fx] = fy, vals += b[i].val;
  }
  for (i = 1; i <= we; ++i) w[i].val -= V;
  return pair(wcnt, vals);
}
void Solve() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1, x, y, z; i <= m; ++i) {
    scanf("%d %d %d", &x, &y, &z);
    if (x == 1 || y == 1)
      vis[x + y - 1] = 1, w[++we] = (Edge){x, y, z, i};
    else
      b[++be] = (Edge){x, y, z, i};
  }
  std ::sort(w + 1, w + we + 1), std ::sort(b + 1, b + be + 1);
  int cnt;
  cnt = 0;
  for (int i = 2; i <= n; ++i) cnt += vis[i];
  if (cnt < k) puts("-1"), exit(0);
  cnt = 0, dsu.clr();
  for (int i = 1, fx, fy; i <= be; ++i) {
    fx = dsu.getfa(b[i].x), fy = dsu.getfa(b[i].y);
    if (fx != fy) dsu.fa[fx] = fy;
  }
  for (int i = 2; i <= n; ++i) vis[i] = 0;
  for (int i = 2; i <= n; ++i) vis[dsu.getfa(i)] = 1;
  for (int i = 2; i <= n; ++i) cnt += vis[i];
  if (cnt > k) puts("-1"), exit(0);
  b[be + 1].val = INT_MAX;
  int l = -1e5, r = 1e5;
  while (l <= r) {
    int mid = l + r >> 1;
    pair ret = Kruskal(mid);
    if (ret.wcnt <= k)
      slp = mid, r = mid - 1;
    else
      l = mid + 1;
  }
}
}  // namespace wqs
namespace construct {
int eval[maxn], evis[maxm], eid[maxn], head[maxn], tot;
struct Edge {
  int next, to;
} e[maxn << 1];
void add_edge(int x, int y) { e[++tot] = (Edge){head[x], y}, head[x] = tot; }
void DFS(int u, int F, int rt) {
  dsu.fa[u] = rt;
  for (int i = head[u], v; v = e[i].to, i; i = e[i].next)
    if (v != F) DFS(v, u, rt);
}
void Solve() {
  printf("%d\n", n - 1);
  int wcnt = 0, fx, fy, i, j;
  dsu.clr();
  for (i = 1; i <= we; ++i) w[i].val += slp;
  for (i = 1, j = 1;; ++i) {
    while (j <= we && w[j].val <= b[i].val) {
      fx = dsu.getfa(w[j].x), fy = dsu.getfa(w[j].y);
      if (fx ^ fy)
        dsu.fa[fx] = fy, eval[w[j].x + w[j].y - 1] = w[j].val,
        evis[eid[w[j].x + w[j].y - 1] = w[j].id] = 1, ++wcnt;
      ++j;
    }
    if (i == be + 1) break;
    fx = dsu.getfa(b[i].x), fy = dsu.getfa(b[i].y);
    if (fx ^ fy)
      dsu.fa[fx] = fy, add_edge(b[i].x, b[i].y), add_edge(b[i].y, b[i].x),
      evis[b[i].id] = 1;
  }
  dsu.clr();
  for (int i = 1; i <= n; ++i)
    if (eval[i]) DFS(i, 0, i);
  for (i = 1; wcnt > k; ++i) {
    if (evis[b[i].id]) continue;
    int fx = dsu.getfa(b[i].x), fy = dsu.getfa(b[i].y);
    if (fx != fy) {
      if (eval[fx] == b[i].val)
        dsu.fa[fx] = fy, --wcnt, evis[eid[fx]] = 0, evis[b[i].id] = 1;
      else if (eval[fy] == b[i].val)
        dsu.fa[fy] = fx, --wcnt, evis[eid[fy]] = 0, evis[b[i].id] = 1;
    }
  }
  for (int i = 1; i <= m; ++i)
    if (evis[i]) printf("%d ", i);
}
}  // namespace construct
int main() { return wqs::Solve(), construct::Solve(), 0; }
