#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 10;
const int inf = 1 << 30;
int g[N][N], dis[N], clo[N], pre[N], fst[N], mx[N], id[N][N];
int n, m, k;
int Prim(int src, int id) {
  dis[src] = 0;
  int ans = 0;
  while (1) {
    int u = -1;
    for (int i = 1; i < n; i++) {
      if (!clo[i] && dis[i] != inf) {
        if (u == -1 || dis[u] > dis[i]) u = i;
      }
    }
    if (u == -1) break;
    clo[u] = id;
    ans += dis[u];
    for (int i = 1; i < n; i++)
      if (!clo[i] && g[u][i] != 0 && dis[i] > g[u][i]) {
        pre[i] = u;
        dis[i] = g[u][i];
      }
  }
  return ans;
}
void dfs(int u, int f) {
  if (u == 0) return;
  dfs(pre[u], u);
  pre[u] = f;
}
int vis[N], sta[N], top;
void update() {
  memset(vis, 0, sizeof(vis));
  vis[0] = 1;
  mx[0] = 0;
  for (int i = 1; i < n; i++) {
    int j = i;
    top = 0;
    while (1) {
      sta[top++] = j;
      if (vis[j]) break;
      j = pre[j];
    }
    for (int j = top - 2; j >= 0; j--) {
      mx[sta[j]] = max(mx[sta[j + 1]], g[sta[j]][sta[j + 1]]);
      vis[sta[j]] = 1;
    }
  }
}
void Solve() {
  for (int i = 0; i < n; i++) {
    dis[i] = inf;
    clo[i] = pre[i] = fst[i] = 0;
  }
  int res = 0, cnt = 0;
  for (int i = 1; i < n; i++)
    if (!clo[i]) {
      res += Prim(i, ++cnt);
    }
  if (cnt > k) {
    printf("-1\n");
    return;
  }
  for (int i = 1; i < n; i++) {
    int id = clo[i];
    if (g[0][i] != 0 && (!fst[id] || g[0][i] < g[0][fst[id]])) fst[id] = i;
  }
  for (int i = 1; i <= cnt; i++) {
    if (!fst[i]) {
      printf("-1\n");
      return;
    }
  }
  for (int i = 1; i <= cnt; i++) {
    res += g[0][fst[i]];
    g[0][fst[i]] = g[fst[i]][0] = 0;
    dfs(fst[i], 0);
  }
  update();
  k = k - cnt;
  while (k--) {
    int tmp = 0;
    for (int i = 1; i < n; i++)
      if (g[0][i] != 0 && (tmp == 0 || g[0][tmp] - mx[tmp] > g[0][i] - mx[i]))
        tmp = i;
    res = res + g[0][tmp] - mx[tmp];
    g[0][tmp] = g[tmp][0] = 0;
    int p = 0;
    for (int i = tmp; i; i = pre[i])
      if (p == 0 || g[p][pre[p]] < g[i][pre[i]]) p = i;
    pre[p] = 0;
    dfs(tmp, 0);
    update();
  }
  printf("%d\n", n - 1);
  for (int i = 1; i < n; i++) {
    printf("%d", id[i][pre[i]] + 1);
    if (i == n - 1)
      printf("\n");
    else
      printf(" ");
  }
}
int main() {
  while (scanf("%d%d%d", &n, &m, &k) != EOF) {
    memset(g, 0, sizeof(g));
    int cnt = 0;
    for (int i = 0; i < m; i++) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      u--;
      v--;
      if (!g[u][v] || g[u][v] > w) g[u][v] = g[v][u] = w;
      id[u][v] = id[v][u] = i;
      if (u == 0 || v == 0) cnt++;
    }
    if (n > 1 && !k || cnt < k) {
      printf("-1\n");
      continue;
    }
    Solve();
  }
  return 0;
}
