#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
const int MAXM = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int n, m, k, cnt, ecnt;
int fa[MAXN], minE[MAXN];
int in[MAXM];
struct node {
  int u, v, val, id;
  node() {}
  node(int a, int b, int c, int d) : u(a), v(b), val(c), id(d) {}
  bool operator<(const node &a) const { return val < a.val; }
} dp[MAXN], edge[MAXM];
vector<node> head[MAXN];
bool cmp(node a, node b) { return a.id < b.id; }
void add_edge(int u, int v, int val, int id) {
  head[u].push_back(node(u, v, val, id));
}
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
void un(int x, int y) { fa[find(x)] = find(y); }
void kruskal() {
  sort(edge + 1, edge + m + 1);
  for (int i = 1; i <= m; i++) {
    int u = edge[i].u, v = edge[i].v, id = edge[i].id;
    if (u == 1 || v == 1) continue;
    if (find(u) != find(v)) {
      un(u, v);
      in[id] = 1;
    }
  }
  sort(edge + 1, edge + m + 1, cmp);
}
void dfs(int u, int fa) {
  for (int i = 0; i < (int)head[u].size(); i++) {
    int v = head[u][i].v, val = head[u][i].val;
    int id = head[u][i].id;
    if (v == fa || !in[id]) continue;
    if (dp[v].val == -1) {
      if (dp[u].val > val)
        dp[v] = dp[u];
      else {
        dp[v].u = u;
        dp[v].v = v;
        dp[v].val = val;
        dp[v].id = id;
      }
    }
    dfs(v, u);
  }
}
bool solve() {
  for (int i = 0; i < (int)head[1].size(); i++) {
    int v = head[1][i].v, val = head[1][i].val;
    int id = head[1][i].id;
    int co = find(v);
    if (edge[minE[co]].val > val) minE[co] = id;
  }
  for (int i = 2; i <= n; i++)
    if (edge[minE[i]].val != INF) {
      cnt++;
      in[minE[i]] = 1;
    }
  if (cnt > k) return 0;
  for (int i = cnt + 1; i <= k; i++) {
    memset(dp, -1, sizeof dp);
    dp[1].v = -INF;
    for (int j = 0; j < (int)head[1].size(); j++)
      if (in[head[1][j].id]) dp[head[1][j].v].val = -INF;
    dfs(1, -1);
    int minnum = INF, idx, minid;
    for (int j = 0; j < (int)head[1].size(); j++) {
      int v = head[1][j].v, val = head[1][j].val;
      int id = head[1][j].id;
      if (val - dp[v].val < minnum) {
        minnum = val - dp[v].val;
        idx = v;
        minid = id;
      }
    }
    in[minid] = 1;
    in[dp[idx].id] = 0;
  }
  return 1;
}
int main() {
  edge[0].val = INF;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int u, v, val;
    scanf("%d%d%d", &u, &v, &val);
    edge[++ecnt] = node(u, v, val, i);
    add_edge(u, v, val, i);
    add_edge(v, u, val, i);
  }
  kruskal();
  if (!solve()) {
    printf("-1");
    return 0;
  }
  printf("%d\n", n - 1);
  for (int i = 1; i <= m; i++)
    if (in[i]) printf("%d ", i);
}
