#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 3) + (x << 1) + (ch ^ 48);
  return x;
}
int n, m, k;
int num, num1, fx, fy;
int ans[5050];
double offset;
struct Edge {
  int x, y, z, id;
};
Edge a[100010];
bool operator<(const Edge A, const Edge B) {
  return offset * (A.x == 1) + A.z < offset * (B.x == 1) + B.z;
}
int fa[5050];
int find(int x) {
  if (x != fa[x]) return fa[x] = find(fa[x]);
  return x;
}
void Kruskal() {
  sort(a + 1, a + m + 1);
  num = num1 = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    fx = find(a[i].x);
    fy = find(a[i].y);
    if (fx == fy) continue;
    if (a[i].x == 1) num1++;
    fa[fx] = fy;
    ans[++num] = a[i].id;
    if (num == n - 1) return;
  }
}
int main() {
  n = read();
  m = read();
  k = read();
  int x, y, z;
  double l, r, mid;
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    z = read();
    if (x > y) swap(x, y);
    a[i].x = x;
    a[i].y = y;
    a[i].z = z;
    a[i].id = i;
  }
  offset = 0;
  Kruskal();
  if (num < n - 1) {
    printf("-1\n");
    return 0;
  }
  l = -1e5;
  r = 1e5 + 0.3;
  for (;;) {
    if (num1 == k || (num1 > k && r - l < 0.1)) break;
    offset = mid = (l + r) / 2.0;
    Kruskal();
    if (num1 < k)
      r = mid;
    else
      l = mid;
  }
  if (num1 != k) {
    sort(a + 1, a + m + 1);
    num = num1 = 0;
    for (int i = 1; i <= n; i++) fa[i] = i;
    for (int i = 1; i <= m; i++) {
      fx = find(a[i].x);
      fy = find(a[i].y);
      if (num1 + (a[i].x == 1) > k) continue;
      if (fx == fy) continue;
      if (a[i].x == 1) num1++;
      fa[fx] = fy;
      ans[++num] = a[i].id;
      if (num == n - 1) break;
    }
  }
  if (num != n - 1) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", num);
  for (int i = 1; i <= num; i++) printf("%d ", ans[i]);
  return 0;
}
