import java.io.*;
import java.util.*;

public class roads_sm {
    static class DSU {
        int[] p, r;

        public DSU(int n) {
            p = new int[n];
            r = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = i;
            }
        }

        int get(int x) {
            if (p[x] == x) {
                return x;
            }
            return p[x] = get(p[x]);
        }

        void union(int a, int b) {
            assert a != b;
            a = get(a);
            b = get(b);
            if (a == b) {
                return;
            }
            if (r[a] > r[b]) {
                p[b] = a;
            } else if (r[a] < r[b]) {
                p[a] = b;
            } else {
                p[a] = b;
                r[b]++;
            }
        }

        public int numberOfComponent() {
            int cnt = 0;
            for (int i = 0; i < p.length; i++) {
                if (p[i] == i) {
                    cnt++;
                }
            }
            return cnt;
        }
    }

    static class Edge {
        int a, b;
        int id;

        Edge(int id, int a, int b) {
            this.a = a;
            this.b = b;
            this.id = id;
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        assert 1 <= k && k < n && n <= 1e5;
        assert 1 <= m && m <= 200000;
        DSU check = new DSU(n);
        ArrayList<Edge> zeroEdges = new ArrayList<Edge>();
        ArrayList<Edge> oneEdges = new ArrayList<Edge>();
        for (int i = 0; i < m; i++) {
            int a = nextInt() - 1;
            assert 0 <= a && a < n;
            int b = nextInt() - 1;
            assert 0 <= b && b < n;
            assert a != b;
            int cost = nextInt();
            assert cost == 0 || cost == 1;
            check.union(a, b);
            if (cost == 0) {
                zeroEdges.add(new Edge(i + 1, a, b));
            } else {
                oneEdges.add(new Edge(i + 1, a, b));
            }
        }
        assert check.numberOfComponent() == 1;
        if (oneEdges.size() < k) {
            out.println(-1);
            return;
        }
        DSU zeroComp = new DSU(n);
        for (Edge e : zeroEdges) {
            zeroComp.union(e.a, e.b);
        }
        int zeroCompCnt = zeroComp.numberOfComponent();
        if (zeroCompCnt > k + 1) {
            out.println(-1);
            return;
        }
        DSU result = new DSU(n);
        ArrayList<Integer> answer = new ArrayList<Integer>();
        for (Edge e : oneEdges) {
            if (zeroComp.get(e.a) != zeroComp.get(e.b)) {
                zeroComp.union(e.a, e.b);
                result.union(e.a, e.b);
                answer.add(e.id);
                k--;
            }
        }
        for (Edge e : oneEdges) {
            if (k > 0 && result.get(e.a) != result.get(e.b)) {
                result.union(e.a, e.b);
                answer.add(e.id);
                k--;
            }
        }
        if (k > 0) {
            out.println(-1);
            return;
        }
        for (Edge e : zeroEdges) {
            if (result.get(e.a) != result.get(e.b)) {
                result.union(e.a, e.b);
                answer.add(e.id);
            }
        }
        for (int i : answer) {
            out.print(i + " ");
        }
        out.println();
    }


    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    final String filename = "roads";

    public void run() {
        try {
            br = new BufferedReader(new FileReader(filename + ".in"));
            out = new PrintWriter(filename + ".out");
            solve();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() {
        try {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return null;
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }

    int nextInt() {
        return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) {
        new roads_sm().run();
    }
}
