#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const double INF = 1e18;
const int MOD = 104659;
const double EPS = 1e-9; // Toleranta pentru compararea numerelor reale
struct Muchie {
int to;
double cost; // Am schimbat in double
};
int main() {
ios_base::sync_with_stdio(false);
fin.tie(NULL);
int N, M;
if (!(fin >> N >> M)) return 0;
vector<vector<Muchie>> adj(N + 1);
for (int i = 0; i < M; ++i) {
int x, y;
double c; // Citim ca double
fin >> x >> y >> c;
adj[x].push_back({y, c});
adj[y].push_back({x, c});
}
vector<double> dist(N + 1, INF);
vector<int> ways(N + 1, 0);
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
dist[1] = 0;
ways[1] = 1;
pq.push({0, 1});
while (!pq.empty()) {
double d = pq.top().first;
int u = pq.top().second;
pq.pop();
// Daca am scos o distanta mai mare (cu toleranta), ignoram
if (d > dist[u] + EPS) continue;
for (auto& muchie : adj[u]) {
int v = muchie.to;
double cost = muchie.cost;
// Cazul 1: Am gasit un drum mai scurt
if (dist[u] + cost < dist[v] - EPS) {
dist[v] = dist[u] + cost;
ways[v] = ways[u];
pq.push({dist[v], v});
}
// Cazul 2: Am gasit un alt drum de aceeasi lungime minima
else if (abs((dist[u] + cost) - dist[v]) <= EPS) {
ways[v] = (ways[v] + ways[u]) % MOD;
}
}
}
for (int i = 2; i <= N; ++i) {
fout << ways[i] << " ";
}
fout << "\n";
return 0;
}