#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
const int MAXM = 100000;
const int INF = 0x3f3f3f3f;
int Fa[MAXN + 10], mn_id[MAXN + 10], id[MAXM + 10], dis[MAXN + 10],
    lis[MAXN + 10], oth[MAXN + 10];
int min_id[MAXN + 10];
bool used[MAXN + 10];
pair<int, pair<int, int> > edg[MAXM + 10];
struct node {
  int v, id;
  node *next;
} Edges[MAXN * 2 + 10], *ecnt = Edges, *adj[MAXN + 10];
void addedge(int u, int v, int id) {
  ++ecnt;
  ecnt->v = v;
  ecnt->id = id;
  ecnt->next = adj[u];
  adj[u] = ecnt;
}
bool cmp(int a, int b) { return edg[a].first < edg[b].first; }
int FindFa(int u) {
  if (!Fa[u]) return u;
  return Fa[u] = FindFa(Fa[u]);
}
bool Union(int x, int y) {
  int f1 = FindFa(x);
  int f2 = FindFa(y);
  if (f1 == f2) return false;
  Fa[f1] = f2;
  return true;
}
void dfs(int u, int fa, int _prev) {
  min_id[u] = _prev;
  for (node *p = adj[u]; p; p = p->next) {
    if (p->v == fa) continue;
    int nex =
        (_prev == -1 || (edg[_prev].first < edg[p->id].first)) ? p->id : _prev;
    dfs(p->v, u, nex);
  }
}
int main() {
  int n, m, k, u, v, w;
  scanf("%d%d%d", &n, &m, &k);
  edg[0].first = INF;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    if (u > v) swap(u, v);
    edg[i] = make_pair(w, make_pair(u, v));
    id[i] = i;
  }
  sort(id + 1, id + 1 + m, cmp);
  int lcnt = 0;
  for (int i = 1; i <= m; i++) {
    if (edg[id[i]].second.first == 1) {
      v = edg[id[i]].second.second;
      if (edg[dis[v]].first > edg[id[i]].first) dis[v] = id[i];
    } else {
      if (Union(edg[id[i]].second.first, edg[id[i]].second.second)) {
        lis[++lcnt] = id[i];
      }
    }
  }
  int ocnt = 0, cur_cnt = 0;
  sort(dis + 1, dis + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (!dis[i]) break;
    if (Union(1, edg[dis[i]].second.second))
      lis[++lcnt] = dis[i], cur_cnt++;
    else
      oth[++ocnt] = dis[i];
  }
  if (lcnt != n - 1 || cur_cnt > k) {
    printf("-1\n");
    return 0;
  }
  while (cur_cnt < k) {
    int diff = INF;
    int rpid = -1, insid = -1;
    memset(adj, 0, sizeof adj);
    ecnt = Edges;
    for (int j = 1; j <= lcnt; j++) {
      addedge(edg[lis[j]].second.first, edg[lis[j]].second.second, lis[j]);
      addedge(edg[lis[j]].second.second, edg[lis[j]].second.first, lis[j]);
    }
    for (node *p = adj[1]; p; p = p->next) dfs(p->v, 1, -1);
    for (int i = 1; i <= ocnt; i++) {
      if (used[i]) continue;
      v = edg[oth[i]].second.second;
      int cur_diff = edg[oth[i]].first - edg[min_id[v]].first;
      if (cur_diff < diff) {
        diff = cur_diff;
        rpid = min_id[v];
        insid = i;
      }
    }
    if (rpid == -1) {
      printf("-1\n");
      return 0;
    }
    used[insid] = true;
    insid = oth[insid];
    cur_cnt++;
    for (int i = 1; i <= lcnt; i++) {
      if (lis[i] == rpid) {
        lis[i] = insid;
        break;
      }
    }
  }
  printf("%d\n", n - 1);
  for (int i = 1; i < n; i++) printf("%d ", lis[i]);
  return 0;
}
