#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
const long double Eps = 1e-6;
const int Inf = 1e9 + 1000;
vector<int> ans;
pair<long double, pair<int, pair<int, int>>> e[MAXN];
pair<pair<long double, pair<int, pair<int, int>>>, int> temp[MAXN];
bool mark[MAXN];
int par[MAXN];
int root(int a) {
  if (par[a] < 0) return a;
  return par[a] = root(par[a]);
}
void merg(int a, int b) {
  a = root(a);
  b = root(b);
  if (a != b) par[a] = b;
}
int check(int n, int m, long double k, bool final = false, int limit = 0) {
  memset(par, -1, sizeof par);
  ans.clear();
  for (int i = 0; i < m; i++)
    temp[i] = {{e[i].first + k * mark[i], e[i].second}, i};
  sort(temp, temp + m);
  int res = 0;
  for (int i = 0; i < m; i++) {
    int x = temp[i].first.second.second.first;
    int y = temp[i].first.second.second.second;
    if (root(x) == root(y) || (res == limit && final && (x * y) == 0)) continue;
    res += ((x * y) == 0);
    merg(x, y);
    ans.push_back(temp[i].second);
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int deg = 0;
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    e[i] = {z, {x * y, {x, y}}};
    mark[i] = ((x * y) == 0);
    deg += mark[i];
  }
  if (deg < k || (k == 0 && n > 1)) return cout << -1 << '\n', 0;
  long double l = -1e9, r = 1e9;
  while (r - l > Eps) {
    long double mid = (r + l) / 2;
    int res = check(n, m, mid);
    if (res < k) r = mid;
    if (res >= k) l = mid;
  }
  check(n, m, l, true, k);
  cout << n - 1 << '\n';
  for (auto u : ans) cout << u + 1 << ' ';
  return 0;
}
