#include <bits/stdc++.h>
using namespace std;
#define N 50001
#define fi first
#define se second
#define MOD 1000000007
#define pb push_back
#define ll long long
#define eps 1.0e-9
#define inf 1e9 + 5
#define double long double
#define pp pair<int,int>
vector< pp > adj[N];
int dis[N],dp[N];
int main()
{
ios::sync_with_stdio(0);
int i,j,k,m,n,t;
cin>>n>>m;
for(i=0;i<m;i++)
{
int u,v,w;
cin>>u>>v>>w;
//u--;v--;
adj[u].pb({w,v});
adj[v].pb({w,v});
}
priority_queue< pp , vector<pp > , greater<pp> > pq;
for(int i=0;i<=n;i++) dis[i] = INT_MAX;
dis[1] = 0;
dp[1] = 1;
pq.push({0,1});
while(!pq.empty())
{
pp tp = pq.top();
int u = tp.se;
int d = tp.fi;
pq.pop();
if(dis[u]<d) continue;
for(i=0;i<adj[u].size();i++)
{
int v = adj[u][i].se;
int w = adj[u][i].fi;
if(d + w <= dis[v] )
{
//dp[v] += dp[u];
if(dis[v]==d+w) dp[v] += dp[u];
if(d + w < dis[v])
{
dis[v] = d + w;
dp[v] = dp[u];
pq.push({dis[v],v});
}
}
}
}
cout<<endl;
for(int i = 1;i<=n;i++)
{
cout<<i<<" dis = "<<dis[i]<<" ways = "<<dp[i]<<endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKI2RlZmluZSBOIDUwMDAxCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwogCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiAKI2RlZmluZSBsbCBsb25nIGxvbmcKIAojZGVmaW5lIGVwcyAxLjBlLTkKI2RlZmluZSBpbmYgMWU5ICsgNQojZGVmaW5lIGRvdWJsZSBsb25nIGRvdWJsZQogCiNkZWZpbmUgcHAgcGFpcjxpbnQsaW50PgoKdmVjdG9yPCBwcCA+IGFkaltOXTsKaW50IGRpc1tOXSxkcFtOXTsKCmludCBt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