#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 1;
const int N = 5e3 + 1;
int tot = 0, cnt = 0;
int n, m, k;
vector<pair<int, int>> adj[N];
set<pair<int, int>> t[N];
int p[N], cst[N];
void dfs(int v) {
  for (auto to = t[v].begin(); to != t[v].end(); to++) {
    int u = to->first;
    if (u != p[v]) {
      p[u] = v;
      cst[u] = to->second;
      dfs(u);
    }
  }
}
int solve(int v) {
  memset(p, -1, sizeof(p));
  memset(cst, -1, sizeof(cst));
  dfs(0);
  int max_w = 0, ans = -1;
  while (p[v] != 0) {
    if (cst[v] > max_w) {
      max_w = cst[v];
      ans = v;
    }
    v = p[v];
  }
  if (ans == -1) {
    cnt++;
    return inf;
  }
  t[ans].erase(make_pair(p[ans], max_w));
  t[p[ans]].erase(make_pair(ans, max_w));
  return max_w;
}
void prim() {
  vector<int> d(n, inf), par(n, -1);
  vector<bool> vis(n, false);
  set<pair<int, int>> q;
  for (int i = 1; i < n; i++) {
    if (vis[i]) continue;
    d[i] = 0;
    q.insert(make_pair(d[i], i));
    while (!q.empty()) {
      int v = q.begin()->second;
      vis[v] = true;
      tot += q.begin()->first;
      q.erase(q.begin());
      if (par[v] != -1) {
        t[v].insert(make_pair(par[v], d[v]));
        t[par[v]].insert(make_pair(v, d[v]));
      }
      for (auto to : adj[v]) {
        int u = to.first, c = to.second;
        if (!vis[u] && c < d[u]) {
          q.erase(make_pair(d[u], u));
          d[u] = c;
          par[u] = v;
          q.insert(make_pair(d[u], u));
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> k;
  map<pair<int, int>, int> idmap;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    if (u > v) swap(u, v);
    u--;
    v--;
    if (u != 0) adj[v].push_back(make_pair(u, c));
    adj[u].push_back(make_pair(v, c));
    idmap[make_pair(u, v)] = i + 1;
    idmap[make_pair(v, u)] = i + 1;
  }
  prim();
  if ((int)adj[0].size() < k) return puts("-1"), 0;
  sort(adj[0].begin(), adj[0].end(),
       [&](pair<int, int> I, pair<int, int> J) { return I.second < J.second; });
  vector<pair<int, pair<int, int>>> a;
  for (auto out : adj[0]) {
    a.push_back(make_pair(out.second - solve(out.first), out));
    t[0].insert(out);
    t[out.first].insert(make_pair(0, out.second));
  }
  sort(a.begin(), a.end());
  vector<int> d(n, inf), vis(n, false), par(n, -1);
  vis[0] = true;
  set<pair<int, int>> q;
  vector<int> eddie;
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int u = a[i].second.first, c = a[i].second.second;
    vis[u] = true;
    d[u] = c;
    ans += c;
    q.insert(make_pair(0, u));
    eddie.push_back(idmap[make_pair(0, u)]);
  }
  while (!q.empty()) {
    int v = q.begin()->second;
    vis[v] = true;
    ans += q.begin()->first;
    q.erase(q.begin());
    if (par[v] != -1) {
      eddie.push_back(idmap[make_pair(par[v], v)]);
    }
    for (auto to : adj[v]) {
      int u = to.first, c = to.second;
      if (!vis[u] && c < d[u]) {
        q.erase(make_pair(d[u], u));
        d[u] = c;
        par[u] = v;
        q.insert(make_pair(d[u], u));
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (!vis[i]) {
      return puts("-1"), 0;
    }
  cout << eddie.size() << "\n";
  for (auto u : eddie) {
    cout << u << " ";
  }
  return 0;
}
