#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, c, p, tip, next;
} g[50005 * 4], a[50005 * 2];
int head[50005], cnt, e, limit, n, m, vv[50005], vis[50005], u[50005],
    num[50005];
int d[50005], pos[50005], s, f[50005];
int cmp(node a, node b) { return a.c < b.c; }
void add(int a, int b, int c, int i) {
  g[cnt].u = a, g[cnt].v = b, g[cnt].c = c, g[cnt].next = head[a], g[cnt].p = i;
  g[cnt].tip = 0;
  head[a] = cnt++;
}
int getf(int a) {
  if (a == f[a]) return a;
  return f[a] = getf(f[a]);
}
void dfs(int u, int s, int l) {
  d[u] = s;
  pos[u] = l;
  vv[u] = 1;
  int i, j;
  for (i = head[u]; i + 1; i = g[i].next) {
    j = g[i].v;
    if (!vv[j] && !g[i].tip) {
      int k = l;
      if (g[i].c > s) k = i;
      dfs(j, max(g[i].c, s), k);
    }
  }
}
void work() {
  int i, k;
  memset(vv, 0, sizeof(vv));
  for (i = 1; i <= n; i++)
    if (vis[i]) dfs(i, 0, 0);
  while (e < limit) {
    int min = 0xfffffff;
    k = 0;
    for (i = 2; i <= n; i++) {
      if (vis[i] || !u[i]) continue;
      if (min > u[i] - d[i]) {
        min = u[i] - d[i];
        k = i;
      }
    }
    if (k == 0) break;
    vis[k] = 1;
    s += min;
    d[k] = 0;
    g[pos[k]].tip = 1;
    g[pos[k] ^ 1].tip = 1;
    memset(vv, 0, sizeof(vv));
    for (i = 1; i <= n; i++)
      if (vis[i]) dfs(i, 0, 0);
    e++;
  }
}
int main() {
  int i;
  while (~scanf("%d%d%d", &n, &m, &limit)) {
    s = 0;
    for (i = 0; i < m; i++) {
      scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].c);
      a[i].p = i;
      a[i].tip = 0;
      if (a[i].u == 1) u[a[i].v] = a[i].c, num[a[i].v] = i;
      if (a[i].v == 1) u[a[i].u] = a[i].c, num[a[i].u] = i;
    }
    sort(a, a + m, cmp);
    for (i = 1; i <= n; i++) f[i] = i;
    for (i = 0; i < m; i++) {
      if (a[i].u == 1 || a[i].v == 1) continue;
      int f1 = getf(a[i].u), f2 = getf(a[i].v);
      if (f1 == f2) continue;
      s += a[i].c;
      if (f1 > f2) swap(f1, f2);
      f[f2] = f1;
      a[i].tip = 1;
    }
    e = 0;
    memset(vis, 0, sizeof(vis));
    for (i = 0; i < m; i++) {
      if (a[i].u == 1) {
        int f1 = getf(a[i].v);
        if (f1 == 1) continue;
        s += a[i].c;
        a[i].tip = 1;
        vis[a[i].v] = 1;
        f[f1] = 1;
        e++;
      } else if (a[i].v == 1) {
        int f1 = getf(a[i].u);
        if (f1 == 1) continue;
        s += a[i].c;
        a[i].tip = 1;
        vis[a[i].u] = 1;
        f[f1] = 1;
        e++;
      }
      if (e == limit) break;
    }
    cnt = 0;
    memset(head, -1, sizeof(head));
    for (i = 0; i < m; i++) {
      if (a[i].tip && a[i].u != 1 && a[i].v != 1) {
        add(a[i].u, a[i].v, a[i].c, a[i].p);
        add(a[i].v, a[i].u, a[i].c, a[i].p);
      }
    }
    for (i = 2; i <= n; i++) {
      int f1 = getf(i);
      if (f1 != 1) break;
    }
    if (i != n + 1) {
      printf("-1\n");
      continue;
    }
    work();
    if (e != limit) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", n - 1);
    for (i = 2; i <= n; i++)
      if (vis[i]) printf("%d ", num[i] + 1);
    for (i = 0; i < cnt; i++)
      if (!g[i].tip) {
        printf("%d ", g[i].p + 1);
        g[i].tip = g[i ^ 1].tip = 1;
      }
    printf("\n");
  }
  return 0;
}
