import static java.util.Arrays.deepToString;

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

public class roads_nn {
	static class DSU {
		int[] p;
		int[] r;

		public DSU(int n) {
			p = new int[n];
			r = new int[n];
			clear();
		}

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

		boolean union(int x, int y) {
			x = get(x);
			y = get(y);
			if (x == y) {
				return false;
			}
			if (r[x] >= r[y]) {
				if (r[x] == r[y]) {
					r[x]++;
				}
				p[y] = x;
			} else {
				p[x] = y;
			}
			return true;
		}

		void clear() {
			for (int i = 0; i < p.length; i++) {
				p[i] = i;
				r[i] = 0;
			}
		}
	}

	static void solve() throws Exception {
		int verticesCount = nextInt();
		int edgesCount = nextInt();
		int k = nextInt();
		List<Edge> zeroWeightEdges = new ArrayList<Edge>();
		List<Edge> oneWeightEdges = new ArrayList<Edge>();
		for (int i = 0; i < edgesCount; i++) {
			Edge e = new Edge(nextInt() - 1, nextInt() - 1, i);
			if (nextInt() == 0) {
				zeroWeightEdges.add(e);
			} else {
				oneWeightEdges.add(e);
			}
		}
		DSU dsu = new DSU(verticesCount);
		int countComponents = verticesCount;
		for (Edge e : zeroWeightEdges) {
			if (dsu.union(e.from, e.to)) {
				countComponents--;
			}
		}
		if (countComponents > k + 1) {
			out.println(-1);
			return;
		}
		DSU dsu2 = new DSU(verticesCount);
		List<Integer> answer = new ArrayList<Integer>();
		for (Edge e : oneWeightEdges) { // connect components
			if (dsu.union(e.from, e.to)) {
				dsu2.union(e.from, e.to);
				answer.add(e.num);
			}
		}
		for (Edge e : oneWeightEdges) { // get weight equal to k
			if (answer.size() == k) {
				break;
			}
			if (dsu2.union(e.from, e.to)) {
				answer.add(e.num);
			}
		}
		if (answer.size() != k) {
			out.println(-1);
			return;
		}
		for (Edge e : zeroWeightEdges) {
			if (dsu2.union(e.from, e.to)) {
				answer.add(e.num);
			}
		}
		Collections.sort(answer);
		for (int i = 0; i < answer.size(); i++) {
			if (i > 0) {
				out.print(' ');
			}
			out.print(answer.get(i) + 1);
		}
		out.println();
	}

	static class Edge {
		int from;
		int to;
		int num;

		public Edge(int from, int to, int num) {
			this.from = from;
			this.to = to;
			this.num = num;
		}

	}

	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;

	static void debug(Object... a) {
		System.err.println(deepToString(a));
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null) {
				return null;
			}
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}

	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("roads.in"))));
			out = new PrintWriter((new PrintStream("roads.out")));
			solve();
			out.close();
			br.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}