#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const long long INF = 1e18;
const long long mod = 998244353;
const double Pi = acos(-1);
void Fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
struct Edge {
  long long u, v, c;
  Edge(long long u, long long v, long long c) : u(u), v(v), c(c){};
};
long long n, m, k;
long long dsu[5005], dp[5005], father[5005], id[5005];
vector<Edge> E, W, P;
vector<pair<long long, long long> > Adj[5005];
map<pair<long long, long long>, long long> M;
set<long long> Ans;
bool Compare(Edge A, Edge B) { return A.c < B.c; }
long long Root(long long node) {
  return node == dsu[node] ? node : dsu[node] = Root(dsu[node]);
}
void DFS(long long node, long long p) {
  for (auto x : Adj[node]) {
    if (x.first == p) {
      continue;
    }
    father[x.first] = node;
    if (dp[node] < x.second) {
      id[x.first] = x.first;
    } else {
      id[x.first] = id[node];
    }
    dp[x.first] = max(dp[node], x.second);
    DFS(x.first, node);
  }
}
signed main() {
  Fastio();
  cin >> n >> m >> k;
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    dsu[i] = i;
  }
  for (long long i = 1; i <= m; i++) {
    long long u, v, c;
    cin >> u >> v >> c;
    M[make_pair(u, v)] = i;
    M[make_pair(v, u)] = i;
    P.emplace_back(u, v, c);
    if (u == 1 or v == 1) {
      W.emplace_back(min(u, v), max(u, v), c);
      continue;
    }
    E.emplace_back(u, v, c);
  }
  sort(E.begin(), E.end(), Compare);
  sort(W.begin(), W.end(), Compare);
  for (auto x : E) {
    if (Root(x.u) == Root(x.v)) {
      continue;
    }
    Adj[x.u].emplace_back(x.v, x.c);
    Adj[x.v].emplace_back(x.u, x.c);
    cnt++;
    dsu[Root(x.u)] = Root(x.v);
  }
  for (auto x : W) {
    if (x.u == 1 or x.v == 1) {
      if (Root(x.u) != Root(x.v)) {
        Adj[x.u].emplace_back(x.v, x.c);
        Adj[x.v].emplace_back(x.u, x.c);
        cnt++;
        k--;
        dsu[Root(x.u)] = Root(x.v);
      }
    }
  }
  if (cnt != n - 1 or k < 0) {
    cout << -1;
    return 0;
  }
  for (long long i = 1; i <= n; i++) {
    for (auto x : Adj[i]) {
      Ans.insert(M[make_pair(i, x.first)]);
    }
  }
  long long ans = 0;
  while (k--) {
    for (long long i = 1; i <= n; i++) {
      dp[i] = 0;
    }
    dp[1] = -1e10;
    for (auto x : Adj[1]) {
      dp[x.first] = -1e12;
      DFS(x.first, 1);
    }
    long long temp = 2e10, ii = -1, ww = 0;
    for (auto x : W) {
      if (x.c - dp[x.v] < temp) {
        temp = x.c - dp[x.v];
        ii = x.v;
        ww = x.c;
      }
    }
    if (ii == -1) {
      cout << -1;
      return 0;
    }
    Adj[1].emplace_back(ii, ww);
    Adj[ii].emplace_back(1, ww);
    ii = id[ii];
    for (long long i = 0; i < Adj[ii].size(); i++) {
      if (Adj[ii][i].first == father[ii]) {
        Adj[ii].erase(Adj[ii].begin() + i);
        break;
      }
    }
    for (long long i = 0; i < Adj[father[ii]].size(); i++) {
      if (Adj[father[ii]][i].first == ii) {
        Adj[father[ii]].erase(Adj[father[ii]].begin() + i);
        break;
      }
    }
    Ans.clear();
    for (long long i = 1; i <= n; i++) {
      for (auto x : Adj[i]) {
        Ans.insert(M[make_pair(i, x.first)]);
      }
    }
    long long ans = 0;
  }
  Ans.clear();
  ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (auto x : Adj[i]) {
      Ans.insert(M[make_pair(i, x.first)]);
    }
  }
  cout << Ans.size() << '\n';
  for (auto x : Ans) {
    cout << x << ' ';
    ans += P[x - 1].c;
  }
}
