#include <bits/stdc++.h>
using namespace std;
const int N = 5005, M = 2e5 + 5;
const int INF = 0x3f3f3f3f;
struct node {
  int u, v, w, nxt, pos;
} e[M], edge[M];
int head[N], mcnt;
void add_edge(int u, int v, int w, int pos) {
  mcnt++;
  edge[mcnt].u = u;
  edge[mcnt].v = v;
  edge[mcnt].w = w;
  edge[mcnt].pos = pos;
  edge[mcnt].nxt = head[u];
  head[u] = mcnt;
}
int n, m, k;
int fa[N];
int dp[N];
bool vis[M];
bool cmp(node a, node b) { return a.w < b.w; }
int find_father(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find_father(fa[x]);
}
void merge(int x, int y) {
  int f1 = find_father(x), f2 = find_father(y);
  fa[f1] = f2;
}
void Kruscal() {
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int u = e[i].u, v = e[i].v;
    if (u == 1 || v == 1) continue;
    if (find_father(u) != find_father(v)) {
      merge(u, v);
      vis[e[i].pos] = 1;
    }
  }
}
void dfs(int u, int fa) {
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].v, w = edge[i].w;
    int d = (dp[u] == -INF || dp[u] == -1) ? -INF : edge[dp[u]].w;
    if (v == fa || !vis[edge[i].pos]) continue;
    if (dp[v] == -1) {
      if (d > w)
        dp[v] = dp[u];
      else {
        dp[v] = i;
      }
    }
    dfs(v, u);
  }
}
int me[N];
void solve() {
  for (int i = head[1]; i; i = edge[i].nxt) {
    int v = edge[i].v, w = edge[i].w;
    int f = find_father(v);
    if (me[f] == -1 || edge[me[f]].w > w) {
      me[f] = i;
    }
  }
  int du = 0;
  for (int i = 1; i <= n; i++)
    if (me[i] != -1) {
      du++;
      vis[edge[me[i]].pos] = 1;
    }
  int cnt = 0;
  for (int i = head[1]; i; i = edge[i].nxt) cnt++;
  if (cnt < k || du > k) {
    printf("-1");
    exit(0);
  }
  for (int t = du + 1; t <= k; t++) {
    memset(dp, -1, sizeof dp);
    dp[1] = -INF;
    for (int i = head[1]; i; i = edge[i].nxt)
      if (vis[edge[i].pos]) {
        dp[edge[i].v] = -INF;
      }
    dfs(1, -1);
    int id, mn = INF;
    for (int i = head[1]; i; i = edge[i].nxt) {
      if (dp[edge[i].v] != -INF && mn > edge[i].w - edge[dp[edge[i].v]].w) {
        mn = edge[i].w - edge[dp[edge[i].v]].w;
        id = i;
      }
    }
    vis[edge[id].pos] = 1;
    vis[edge[dp[edge[id].v]].pos] = 0;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    e[i].u = u, e[i].v = v, e[i].w = w, e[i].pos = i;
    add_edge(u, v, w, i);
    add_edge(v, u, w, i);
  }
  memset(me, -1, sizeof me);
  Kruscal();
  solve();
  printf("%d\n", n - 1);
  for (int i = 1; i <= m; i++)
    if (vis[e[i].pos]) printf("%d ", e[i].pos);
}
