import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Kostry {
static class Hrana {
int z;
int k;
int c;
@Override
public String toString() {
return "[" + z + ", " + k + "]";
}
}
static class Graf {
int n;
List<Hrana> hrany;
}
static class TriedicHran implements Comparator<Hrana> {
@Override
public int compare(Hrana o1, Hrana o2) {
return Integer.compare(o1.c, o2.c);
}
}
public static Graf nacitajGraf(String subor) {
Graf g = new Graf();
Scanner citac = null;
try {
citac = new Scanner(new File(subor));
g.n = citac.nextInt();
g.hrany = new ArrayList<Hrana>();
int m = citac.nextInt();
for (int i=0; i<m; i++) {
Hrana h = new Hrana();
h.z = citac.nextInt()-1;
h.k = citac.nextInt()-1;
h.c = citac.nextInt();
g.hrany.add(h);
}
} catch (Exception e) {
return null;
} finally {
if (citac != null) {
citac.close();
}
}
return g;
}
public static List<Hrana> kruskal(Graf g) {
Collections.sort(g.hrany, new TriedicHran());
List<Hrana> kostra = new ArrayList<Hrana>();
int[] id = new int[g.n];
for (int i=0; i<id.length; i++)
id[i] = i;
for(Hrana h: g.hrany)
if (id[h.z] != id[h.k]) {
kostra.add(h);
int idZaciatku = id[h.z];
for (int i=0; i<id.length; i++)
if (id[i] == idZaciatku) {
id[i] = id[h.k];
}
}
return kostra;
}
/**
* @param args
*/
public static void main(String[] args) {
Graf g = nacitajGraf("graf.txt");
System.out.println(g.n + " " + g.hrany.size());
System.out.println(kruskal(g));
}
}