# 頂点の数（N）および辺の数（M）を入力する
N, M = map(int, input().split())

# 辺の長さを格納する辞書（dic_edge_dist）を設定する
dic_edge_dist = {(i, j) : float("inf") for i in range(1, N + 1) for j in range(1, N + 1)}
for i in range(1, N + 1):
    dic_edge_dist[(i, i)] = 0
# 辺を格納するリスト（list_edge）を設定する
list_edge = []

def warshall_floyd(dic_edge_dist):
    dic_shortest_dist = dic_edge_dist.copy()
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                dic_shortest_dist[(j, k)] = min(dic_shortest_dist[(j, k)], dic_shortest_dist[(j, i)] + dic_shortest_dist[(i, k)])
    return dic_shortest_dist

# 各辺について、、
for _ in range(M):
    # 頂点および辺の長さを入力する
    a, b, c = map(int, input().split())
    # dic_edge_distに辺の長さを格納する
    dic_edge_dist[(a, b)] = c
    dic_edge_dist[(b, a)] = c
    # list_edgeに辺を格納する
    list_edge.append((min(a, b), max(a, b)))

dic_shortest_dist = warshall_floyd(dic_edge_dist)
    
edge_count = 0
for i, j in list_edge:
    for k in range(1, N + 1):
        if dic_shortest_dist[(k, i)] + dic_edge_dist[(i, j)] == dic_shortest_dist[(k, j)]:
            edge_count += 1
            print(i, j, k)
            break
        if dic_shortest_dist[(k, j)] + dic_edge_dist[(j, i)] == dic_shortest_dist[(k, i)]:
            edge_count += 1
            print(i, j, k)
            break

print(dic_edge_dist)
print(dic_shortest_dist)
print(len(list_edge) - edge_count)