#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const long long INF = 999999999;
int n, m;
vector<vector<pair<int, double>>> adj;
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
vector<int> tata, dmin;
vector<double> d;
bool egalitate(double a, double b, double absEpsilon = 1e-12, double relEpsilon = 1e-9) {
if (a == b) return true;
double diff = fabs(a - b);
// Toleranta absoluta pentru numere fractionare
if (diff <= absEpsilon) return true;
// Toleranta relativa la cea mai mare limita
return diff <= max(fabs(a), fabs(b)) * relEpsilon;
}
void dijkstra(int s) {
d[s] = 0;
dmin[s] = 1;
pq.push({0,s});
while (!pq.empty()) {
auto [dist, u] = pq.top();
pq.pop();
if (dist > d[u]) continue;
for (auto& [v,w] : adj[u]) {
if (d[u] + w < d[v]) {
tata[v] = u;
d[v] = d[u] + w;
dmin[v] = dmin[u];
pq.push({d[v],v});
} else if (egalitate(d[u] + w, d[v])) dmin[v] += dmin[u];
}
}
}
int main()
{
fin >> n >> m;
adj.resize(n + 5);
d.resize(n + 5, INF);
tata.resize(n + 5);
dmin.resize(n + 5);
for (int i = 0; i < m; i++) {
int u, v, w;
fin >> u >> v >> w;
adj[u].push_back({v,log(w)});
adj[v].push_back({u,log(w)});
}
dijkstra(1);
for (int i = 2; i <= n; i++)
fout << dmin[i] % 104659 << " ";
return 0;
}