#include<bits/stdc++.h>
#define ll long long
#define mo 2147483647
using namespace std;
ll n,m,tot,head[1005],vis[1005],cnt[1005],dis[1005],ans=1;
struct node{
ll to,dis;
};
vector<node>e[1005];
void spfa(){
memset(dis,0x3f,sizeof(dis));
queue<ll>q;
vis[1]=1;
dis[1]=0;
q.push(1);
while(!q.empty()){
ll u=q.front();
vis[u]=0;
q.pop();
for(ll i=0;i<e[u].size();i++){
ll v=e[u][i].to,w=e[u][i].dis;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
if(!vis[v]){
vis[v]=1;
q.push(v);
}
}
}
}
}
int main(){
cin>>n>>m;
for(ll i=1;i<=m;i++){
ll u,v,w;
cin>>u>>v>>w;
e[u].push_back({v,w});
e[v].push_back({u,w});
}
spfa();
for(ll i=1;i<=n;i++){
for(ll j=0;j<e[i].size();j++){
int v=e[i][j].to;
if(dis[i]+e[i][j].dis==dis[v])cnt[v]++;
}
}
for(ll i=2;i<=n;i++){
ans*=cnt[i];
ans%=mo;
}
cout<<ans<<endl;
return 0;
}