#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x, y, w, r;
  bool vis;
  bool operator<(const struct edge T) const { return w < T.w; }
};
struct Edge {
  int y, w, next, r;
  int num;
  bool vis;
} e[5002 * 2];
edge a[100002];
int n, m, k, pa[5002], cnt, he[5002];
int la[5002], lan[5002];
vector<int> v;
int find(int x) { return pa[x] == x ? x : pa[x] = find(pa[x]); }
void addEdge(int x, int y, int z, int zz) {
  e[cnt].num = zz;
  e[cnt].vis = 1;
  e[cnt].r = cnt;
  e[cnt].y = y;
  e[cnt].w = z;
  e[cnt].next = he[x];
  he[x] = cnt++;
  e[cnt].num = zz;
  e[cnt].vis = 1;
  e[cnt].r = cnt;
  e[cnt].y = x;
  e[cnt].w = z;
  e[cnt].next = he[y];
  he[y] = cnt++;
}
void init() {
  cnt = 0;
  memset(he, -1, sizeof(he));
}
void dfs(int u, int fa) {
  for (int i = he[u]; i != -1; i = e[i].next) {
    Edge t = e[i];
    if (t.y == fa || !t.vis) continue;
    if (u != 1) {
      la[t.y] = t.w;
      lan[t.y] = t.r;
      if (la[t.y] < la[u]) {
        la[t.y] = la[u];
        lan[t.y] = lan[u];
      }
    }
    dfs(t.y, u);
  }
}
int main() {
  init();
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].w);
    if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
    a[i].r = i;
  }
  sort(a, a + m);
  for (int i = 1; i <= n; i++) pa[i] = i;
  for (int i = 0; i < m; i++) {
    if (a[i].x == 1)
      v.push_back(i);
    else {
      int x = find(a[i].x);
      int y = find(a[i].y);
      if (x != y) {
        pa[x] = y;
        a[i].vis = 1;
      }
    }
  }
  int tot = 0, ca = 0;
  for (int i = 2; i <= n; i++)
    if (find(i) == i) tot++;
  if (tot > v.size() || tot > k) {
    puts("-1");
    return 0;
  }
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    int t = find(a[*it].y);
    if (t != 1) {
      pa[t] = 1;
      a[*it].vis = 1;
      ca++;
    }
  }
  if (ca != tot) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < m; i++)
    if (a[i].vis) addEdge(a[i].x, a[i].y, a[i].w, i);
  while (tot < k) {
    memset(la, 0, sizeof(la));
    memset(lan, 0, sizeof(lan));
    dfs(1, 0);
    int minx = 0x7fffffff, tt;
    for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
      if (a[*it].vis) continue;
      if (minx > a[*it].w - la[a[*it].y]) {
        tt = *it;
        minx = a[*it].w - la[a[*it].y];
      }
    }
    addEdge(1, a[tt].y, a[tt].w, tt);
    e[lan[a[tt].y]].vis = 0;
    e[lan[a[tt].y] ^ 1].vis = 0;
    a[e[lan[a[tt].y]].num].vis = 0;
    a[e[lan[a[tt].y] ^ 1].num].vis = 0;
    a[tt].vis = 1;
    k--;
  }
  printf("%d\n", n - 1);
  for (int i = 0; i < m; i++) {
    if (a[i].vis) printf("%d ", a[i].r + 1);
  }
  return 0;
}
