#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
const int MAXM = 100000;
const int INF = 0x3f3f3f3f;
template <class T>
void Read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = 0;
  while (c < '0' || '9' < c) {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (flag) x = -x;
}
struct node {
  int v, w, id;
  bool vis;
  node *bck, *nxt;
} * adj[MAXN + 10], Edges[MAXM * 2 + 10], *New = Edges, *zero = Edges;
void addedges(int u, int v, int w, int id) {
  node *p = ++New;
  p->v = v;
  p->w = w;
  p->id = id;
  p->vis = false;
  p->bck = New + 1;
  p->nxt = adj[u];
  adj[u] = p;
  p = ++New;
  p->v = u;
  p->w = w;
  p->id = id;
  p->vis = false;
  p->bck = New - 1;
  p->nxt = adj[v];
  adj[v] = p;
}
int u[MAXM + 10], v[MAXM + 10], w[MAXM + 10];
bool used[MAXM + 10];
int dist[MAXN + 10], id[MAXN + 10];
int n, m, k;
bool cmp(const int &a, const int &b) { return w[a] < w[b]; }
int rt[MAXN + 10];
inline int find(int x) { return rt[x] == x ? x : rt[x] = find(rt[x]); }
inline bool merge(int a, int b) {
  int rt1 = find(a), rt2 = find(b);
  if (rt1 == rt2)
    return false;
  else {
    rt[rt1] = rt2;
    return true;
  }
}
int pos[MAXM + 10];
void kruskal_o1() {
  int res = n - 1;
  for (int i = 1; i <= m; ++i) {
    if (u[pos[i]] == 1 || v[pos[i]] == 1) continue;
    if (merge(u[pos[i]], v[pos[i]])) {
      addedges(u[pos[i]], v[pos[i]], w[pos[i]], pos[i]);
      if (--res == 1) break;
    }
  }
}
vector<int> ans;
bool vis[MAXN + 10];
int val[MAXN + 10];
node *pre[MAXN + 10];
void dfs(int x, int f, int mxv, node *&mxid) {
  val[x] = mxv, pre[x] = mxid;
  for (node *p = adj[x]; p != NULL; p = p->nxt) {
    if (p->v == f || p->vis) continue;
    dfs(p->v, x, max(mxv, p->w), p->w > mxid->w ? p : mxid);
  }
}
void getans(int x, int f) {
  for (node *p = adj[x]; p != NULL; p = p->nxt) {
    if (p->v == f || p->vis) continue;
    ans.push_back(p->id);
    getans(p->v, x);
  }
}
int main() {
  Read(n), Read(m), Read(k);
  memset(dist, 0x3f, sizeof(dist));
  for (int i = 1; i <= m; ++i) Read(u[i]), Read(v[i]), Read(w[i]);
  for (int i = 1; i <= m; ++i) pos[i] = i;
  sort(pos + 1, pos + m + 1, cmp);
  for (int i = 1; i <= n; ++i) rt[i] = i;
  kruskal_o1();
  int d = 0;
  for (int i = 1; i <= m && d < k; ++i)
    if (u[pos[i]] == 1 || v[pos[i]] == 1) {
      int t = u[pos[i]] + v[pos[i]] - 1;
      if (1 == find(t)) continue;
      rt[find(t)] = 1;
      used[pos[i]] = true;
      vis[t] = true;
      addedges(1, t, w[pos[i]], pos[i]);
      ++d;
    }
  for (int i = 1; i <= m; ++i) {
    if (used[i]) continue;
    if (u[i] == 1) dist[v[i]] = min(dist[v[i]], w[i]), id[v[i]] = i;
    if (v[i] == 1) dist[u[i]] = min(dist[u[i]], w[i]), id[u[i]] = i;
  }
  for (int i = 2; i <= n; ++i)
    if (vis[i]) dfs(i, 1, 0, zero);
  while (d < k) {
    int p = 0, mnv = INF;
    for (int i = 2; i <= n; ++i)
      if (!vis[i] && mnv > dist[i] - val[i]) mnv = dist[i] - val[i], p = i;
    if (!p) break;
    if (pre[p]) pre[p]->vis = pre[p]->bck->vis = true;
    addedges(1, p, dist[p], id[p]);
    vis[p] = true;
    ++d;
    for (int i = 2; i <= n; ++i)
      if (vis[i]) dfs(i, 1, 0, zero);
  }
  int root = find(1);
  for (int i = 2; i <= n; ++i)
    if (find(i) != root) {
      puts("-1");
      return 0;
    }
  ans.clear();
  getans(1, 0);
  sort(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i)
    printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');
}
