#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const int maxm = 100005;
int n, m, i, j, t, k, s, K, N, head[maxn], ed[maxn], bac[maxm], fat[maxn], tot,
    mx[maxn], pla[maxn], torot[maxn], rotnum[maxn], e1, e2;
struct egg {
  int p1, p2, len, id;
} eg[maxm];
struct Edge {
  int pre, nxt, id;
} lk[(maxm << 1) + (maxn << 1)];
bool cmp(egg x, egg y) { return x.len < y.len; }
int father(int x) { return x == fat[x] ? x : fat[x] = father(fat[x]); }
inline void ins(int x, int y, int iid) {
  lk[y] = (Edge){head[x], lk[head[x]].nxt, iid};
  lk[lk[head[x]].nxt].pre = y;
  lk[head[x]].nxt = y;
}
inline void del(int pl) {
  lk[lk[pl].pre].nxt = lk[pl].nxt;
  lk[lk[pl].nxt].pre = lk[pl].pre;
}
void dfs(int x, int y) {
  if (y == 1) mx[x] = 0, pla[x] = 0;
  for (int i = lk[head[x]].nxt; i != ed[x]; i = lk[i].nxt) {
    int des = eg[lk[i].id].p1 + eg[lk[i].id].p2 - x;
    if (des == y) continue;
    mx[des] = mx[x];
    pla[des] = pla[x];
    if (mx[des] < eg[lk[i].id].len)
      mx[des] = eg[lk[i].id].len, pla[des] = lk[i].id;
    dfs(des, x);
  }
  if (y != 1) {
    if (rotnum[x] && s > torot[x] - mx[x] && pla[x]) {
      s = torot[x] - mx[x];
      e1 = rotnum[x];
      e2 = pla[x];
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  memset(torot, 0x3f3f3f3f, sizeof(torot));
  for (i = 1; i <= m; ++i) {
    scanf("%d%d%d", &eg[i].p1, &eg[i].p2, &eg[i].len);
    eg[i].id = i;
  }
  sort(eg + 1, eg + m + 1, cmp);
  for (i = 1; i <= n; ++i) {
    fat[i] = i, head[i] = ++tot, ed[i] = ++tot;
    lk[head[i]].nxt = ed[i];
    lk[ed[i]].pre = head[i];
  }
  t = n - 1;
  for (i = 1; i <= m; ++i) {
    if (eg[i].p1 == 1 && torot[eg[i].p2] > eg[i].len)
      torot[eg[i].p2] = eg[i].len, rotnum[eg[i].p2] = i;
    if (eg[i].p2 == 1 && torot[eg[i].p1] > eg[i].len)
      torot[eg[i].p1] = eg[i].len, rotnum[eg[i].p1] = i;
    if (father(eg[i].p1) == father(eg[i].p2) || eg[i].p1 == 1 || eg[i].p2 == 1)
      continue;
    fat[father(eg[i].p1)] = father(eg[i].p2);
    ins(eg[i].p1, ++tot, i);
    ins(eg[i].p2, ++tot, i);
    --t;
    bac[i] = tot - 1;
  }
  if (t > K) {
    puts("-1");
    return 0;
  }
  for (i = 1; i <= m; ++i) {
    if (eg[i].p1 != 1 && eg[i].p2 != 1) continue;
    if (father(eg[i].p1) == father(eg[i].p2)) continue;
    fat[father(eg[i].p1)] = father(eg[i].p2);
    ins(eg[i].p1, ++tot, i);
    ins(eg[i].p2, ++tot, i);
    bac[i] = tot - 1;
  }
  for (i = 1; i <= n; ++i)
    if (father(i) != father(1)) break;
  if (i <= n) {
    puts("-1");
    return 0;
  }
  for (i = t + 1; i <= K; ++i) {
    s = 1919810114;
    e1 = e2 = 0;
    for (j = lk[head[1]].nxt; j != ed[1]; j = lk[j].nxt)
      dfs(eg[lk[j].id].p1 + eg[lk[j].id].p2 - 1, 1);
    del(bac[e2]);
    del(bac[e2] + 1);
    ins(1, ++tot, e1);
    ins(eg[e1].p1 + eg[e1].p2 - 1, ++tot, e1);
    bac[e1] = tot - 1;
  }
  printf("%d\n", n - 1);
  for (i = 1; i <= n; ++i) {
    for (j = lk[head[i]].nxt; j != ed[i]; j = lk[j].nxt)
      if (eg[lk[j].id].p1 == i) {
        printf("%d ", eg[lk[j].id].id);
      }
  }
  puts("");
  return 0;
}
