#include <bits/stdc++.h>
using namespace std;
vector<int> St;
pair<int, int> link[5010];
set<int> S;
int n, m, c1, c2, k, cntb, ans;
struct edge {
  int u, v, w, id;
  edge() {}
  edge(int u1, int v1, int w1, int id1) : u(u1), v(v1), w(w1), id(id1){};
  bool operator<(const edge &a) const { return w < a.w; }
} e[100010], f[5010], dp[5010];
int Adj[5010], nxt[100010], V[100010], val[100010], Id[100010], cp;
void AddEdge(int u, int v, int w, int id) {
  cp++;
  V[cp] = v, val[cp] = w, Id[cp] = id;
  nxt[cp] = Adj[u];
  Adj[u] = cp;
}
int fa[5010], vis[5010];
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
void Kruscal() {
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(e, e + c2);
  for (int i = 0; i < c2; i++)
    if (Find(e[i].u) != Find(e[i].v)) {
      fa[fa[e[i].u]] = fa[e[i].v];
      ans++;
      S.insert(e[i].id);
      AddEdge(e[i].u, e[i].v, e[i].w, e[i].id);
      AddEdge(e[i].v, e[i].u, e[i].w, e[i].id);
    }
}
bool TreeStructure() {
  Kruscal();
  for (int i = 2; i <= n; i++)
    if (!vis[Find(i)]) {
      vis[fa[i]] = 1;
      cntb++;
    }
  if (k < cntb) return 1;
  int cnt3 = 0;
  for (int i = 0; i < c1; i++) {
    int p = Find(f[i].v);
    if (!link[p].first || f[i].w < link[p].first) {
      if (!link[p].first) cnt3++;
      link[p].first = f[i].w;
      link[p].second = f[i].id;
    }
  }
  if (cnt3 < cntb) return 1;
  ans += cnt3;
  for (int i = 0; i < c1; i++) {
    int p = Find(f[i].v);
    if (link[p].second == f[i].id) {
      S.insert(f[i].id);
      St.push_back(f[i].v);
    }
  }
  return 0;
}
void dfs(int u, int pre) {
  for (int i = Adj[u]; i; i = nxt[i])
    if (V[i] != pre) {
      if (dp[u].w > val[i])
        dp[V[i]] = dp[u];
      else
        dp[V[i]] = edge(u, V[i], val[i], Id[i]);
      dfs(V[i], u);
    }
}
void Erase(int x) {
  int u = dp[x].u, v = dp[x].v;
  int i = Adj[u];
  if (V[i] == v)
    Adj[u] = nxt[i];
  else {
    int ls = i;
    i = nxt[i];
    for (; i; ls = i, i = nxt[i])
      if (V[i] == v) {
        nxt[ls] = nxt[i];
        break;
      }
  }
  i = Adj[v];
  if (V[i] == u)
    Adj[v] = nxt[i];
  else {
    int ls = i;
    i = nxt[i];
    for (; i; ls = i, i = nxt[i])
      if (V[i] == u) {
        nxt[ls] = nxt[i];
        break;
      }
  }
}
void TreeK() {
  for (int i = cntb + 1; i <= k; i++) {
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < St.size(); i++) {
      int v = St[i];
      dp[v].w = -1000010;
      dfs(v, 1);
    }
    int mx = -1000010, t, Addid;
    for (int i = 0; i < c1; i++)
      if (dp[f[i].v].w - f[i].w > mx) {
        mx = dp[f[i].v].w - f[i].w;
        t = f[i].v;
        Addid = f[i].id;
      }
    Erase(t);
    St.push_back(t);
    S.insert(Addid);
    S.erase(dp[t].id);
  }
}
int main() {
  int u, v, w;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    if (u == 1 || v == 1) {
      if (v == 1) v = u;
      f[c1++] = edge(1, v, w, i);
    } else
      e[c2++] = edge(u, v, w, i);
  }
  if (TreeStructure()) {
    printf("-1\n");
    return 0;
  }
  TreeK();
  printf("%d\n", ans);
  for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    printf("%d ", *it);
  printf("\n");
}
