#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
const int M = (int)1e5 + 10;
int n, m, k, ans, du;
int E[M][3], id[M], used[M], G[N][N][2], ch[N];
int fa[N], dp[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
bool cmp(int a, int b) { return E[a][2] < E[b][2]; }
void dfs(int u, int pre) {
  for (int j = 1; j <= ch[u]; j++) {
    int v = G[u][j][0], p = G[u][j][1];
    if (v == pre) continue;
    if (u == 1)
      dp[v] = 0;
    else if (E[dp[u]][2] > E[p][2])
      dp[v] = dp[u];
    else
      dp[v] = p;
    dfs(v, u);
  }
}
void del(int u, int v) {
  int pos = 0;
  for (int i = 1; i <= ch[u] && !pos; i++) pos = G[u][i][0] == v ? i : 0;
  for (int i = pos; i < ch[u]; i++)
    G[u][i][0] = G[u][i + 1][0], G[u][i][1] = G[u][i + 1][1];
  ch[u]--;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= m; i++) scanf("%d %d %d", E[i] + 0, E[i] + 1, E[i] + 2);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) id[i] = i;
  sort(id + 1, id + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int p = id[i];
    int a = E[p][0], b = E[p][1];
    if (find(a) != find(b) && a != 1 && b != 1) {
      fa[find(a)] = find(b);
      used[p] = 1;
      G[a][++ch[a]][0] = b, G[a][ch[a]][1] = p;
      G[b][++ch[b]][0] = a, G[b][ch[b]][1] = p;
      ans += E[p][2];
    }
  }
  for (int i = 1; i <= m; i++) {
    int p = id[i];
    int a = E[p][0], b = E[p][1];
    if (find(a) != find(b) && (a == 1 || b == 1)) {
      fa[find(a)] = find(b);
      used[p] = 1;
      G[a][++ch[a]][0] = b, G[a][ch[a]][1] = p;
      G[b][++ch[b]][0] = a, G[b][ch[b]][1] = p;
      ans += E[p][2];
      du++;
    }
  }
  while (du < k) {
    dfs(1, 0);
    int find = 0, tmp = M, _i, _j;
    for (int i = 1; i <= m; i++) {
      int p = id[i];
      int a = E[p][0], b = E[p][1];
      if (used[p]) continue;
      if (a != 1 && b != 1) continue;
      int v = a == 1 ? b : a;
      find = 1;
      if (tmp > E[p][2] - E[dp[v]][2])
        tmp = E[p][2] - E[dp[v]][2], _i = p, _j = dp[v];
    }
    if (!find) break;
    del(E[_j][0], E[_j][1]);
    del(E[_j][1], E[_j][0]);
    int v = E[_i][0] == 1 ? E[_i][1] : E[_i][0];
    G[1][++ch[1]][0] = v, G[1][ch[1]][1] = _i;
    G[v][++ch[v]][0] = 1, G[v][ch[v]][1] = _i;
    du++;
    used[_j] = 0;
    used[_i] = 1;
  }
  if (k != du)
    printf("-1");
  else {
    printf("%d\n", n - 1);
    for (int i = 1; i <= m; i++)
      if (used[i]) printf("%d ", i);
  }
  return 0;
}
