#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int MAXN = 200005;
const int INF = 1050000000;
int c[MAXN];
bool compare(int i, int j) { return c[i] < c[j]; }
struct Restricted_MST {
  int n, lmt;
  vector<pair<pair<int, int>, int> > e;
  int parent[MAXN];
  int to[MAXN], firstEdge[MAXN], nextEdge[MAXN];
  bool choose[MAXN];
  int best[MAXN], candidate[MAXN];
  int a[MAXN], b[MAXN];
  int order[MAXN];
  int adj[MAXN];
  void init(int nn, int limit) {
    n = nn;
    lmt = limit;
    e.clear();
  }
  void addedge(int u, int v, int w) {
    e.push_back(make_pair(make_pair(u, v), w));
  }
  int findRoot(int i) {
    if (parent[i] != i) parent[i] = findRoot(parent[i]);
    return parent[i];
  }
  void addEdge(int i, int u, int v) {
    to[i] = v;
    nextEdge[i] = firstEdge[u];
    firstEdge[u] = i;
  }
  void dfs(int p, int u) {
    for (int i = firstEdge[u]; i != -1; i = nextEdge[i]) {
      if (!choose[i >> 1]) continue;
      int v = to[i];
      if (p == v) continue;
      if (u) {
        best[v] = c[i >> 1];
        candidate[v] = i >> 1;
        if (best[u] > best[v]) {
          best[v] = best[u];
          candidate[v] = candidate[u];
        }
      } else
        best[v] = -INF;
      dfs(u, v);
    }
  }
  void myAddEdge(int i) {
    addEdge(i + i, a[i], b[i]);
    addEdge(i + i + 1, b[i], a[i]);
  }
  vector<int> result;
  void solve() {
    result.clear();
    int m = e.size();
    for (int i = int(0); i < int(m); ++i) {
      a[i] = e[i].first.first;
      b[i] = e[i].first.second;
      c[i] = e[i].second;
      if (a[i] > b[i]) swap(a[i], b[i]);
      order[i] = i;
    }
    sort(order, order + m, compare);
    for (int i = int(0); i < int(n); ++i) parent[i] = i;
    memset(choose, 0, sizeof(choose));
    for (int i = int(0); i < int(m); ++i) {
      int p = order[i];
      if ((!a[p]) || (findRoot(a[p]) == findRoot(b[p]))) continue;
      choose[p] = true;
      parent[findRoot(a[p])] = findRoot(b[p]);
    }
    int component = 0;
    for (int i = int(1); i < int(n); ++i) {
      if (findRoot(i) == i) {
        component += 1;
        best[i] = INF;
      }
    }
    if (component > lmt) {
      result.push_back(-1);
      return;
    }
    memset(adj, -1, sizeof(adj));
    for (int i = int(0); i < int(m); ++i) {
      if (a[i]) continue;
      adj[b[i]] = i;
      int r = findRoot(b[i]);
      if (c[i] < best[r]) {
        best[r] = c[i];
        candidate[r] = i;
      }
    }
    for (int i = int(1); i < int(n); ++i) {
      if (findRoot(i) == i) {
        if (best[i] == INF) {
          result.push_back(-1);
          return;
        }
        choose[candidate[i]] = true;
      }
    }
    memset(firstEdge, -1, sizeof(firstEdge));
    for (int i = int(0); i < int(m); ++i)
      if (choose[i]) myAddEdge(i);
    while (component < lmt) {
      dfs(-1, 0);
      int tmpBest = INF, tmpCandidate;
      for (int i = int(1); i < int(n); ++i) {
        if ((adj[i] == -1) || (best[i] == -INF)) continue;
        if ((c[adj[i]] - best[i]) < tmpBest) {
          tmpBest = c[adj[i]] - best[i];
          tmpCandidate = i;
        }
      }
      if (tmpBest == INF) {
        result.push_back(-1);
        return;
      }
      choose[candidate[tmpCandidate]] = false;
      choose[adj[tmpCandidate]] = true;
      myAddEdge(adj[tmpCandidate]);
      component += 1;
    }
    for (int i = int(0); i < int(m); ++i)
      if (choose[i]) result.push_back(i);
  }
} R;
int main() {
  int n, m, lmt;
  while (scanf("%d%d%d", &n, &m, &lmt) == 3) {
    R.init(n, lmt);
    for (int i = int(0); i < int(m); ++i) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      R.addedge(u - 1, v - 1, w);
    }
    R.solve();
    if ((R.result.size() == 1) && (R.result[0] == -1)) {
      printf("-1\n");
    } else {
      printf("%d\n", R.result.size());
      for (int i = int(0); i < int(R.result.size()); ++i) {
        if (i) printf(" ");
        printf("%d", R.result[i] + 1);
      }
      printf("\n");
    }
  }
}
