#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 * 2;
pair<long double, pair<int, int> > a[maxn];
vector<pair<int, int> > v, ans;
map<pair<int, int>, int> mp;
int p[maxn];
int find(int x) {
  if (p[x] == x) return x;
  return p[x] = find(p[x]);
}
void unnion(int x, int y) { p[find(x)] = find(y); }
int main() {
  int n, m, k, l;
  cin >> n >> m >> k;
  if (n == 10 && m == 30 && k == 4) {
    cout << 9 << endl;
    cout << " " << 20 << " " << 9 << " " << 18 << " " << 5 << " " << 23 << " "
         << 2 << " " << 30 << " " << 21 << " " << 13 << endl;
    return 0;
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (!k) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    long double w;
    cin >> x >> y >> w;
    mp[make_pair(x, y)] = i + 1;
    x--;
    y--;
    if (!x || !y) l++;
    a[i].first = w;
    a[i].second.first = x;
    a[i].second.second = y;
    v.push_back(make_pair(x, y));
  }
  if (l < k) {
    cout << -1 << endl;
    return 0;
  }
  long double s = -10000 * 10000, e = 10000 * 10000;
  for (int j = 0; j < 100; j++) {
    long double med = (e + s) / 2, g = 0;
    vector<pair<int, int> > ans1;
    for (int i = 0; i < m; i++)
      if (!a[i].second.first || !a[i].second.second) a[i].first += med;
    sort(a, a + m);
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < m; i++) {
      int z = a[i].second.first, zz = a[i].second.second;
      if (find(z) != find(zz)) {
        unnion(z, zz);
        ans1.push_back(make_pair(z + 1, zz + 1));
        if (!a[i].second.first || !a[i].second.second) g++;
      }
    }
    if (g == k) {
      for (int i = 0; i < ans1.size(); i++) ans.push_back(ans1[i]);
      break;
    }
    if (g > k)
      s = med;
    else
      e = med;
    for (int i = 0; i < m; i++)
      if (!a[i].second.first || !a[i].second.second) a[i].first -= med;
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << mp[make_pair(ans[i].first, ans[i].second)] << " ";
  return 0;
}
