class Solution {
public:
static const int N=2e4+7, M=8e4+7, mod=1e9+7;
typedef pair<int, int> PII;
int e[M], ne[M], w[M], h[N], idx;
int n;
bool st[N];
long long dist[N];
int memo[N];
void add(int a, int b, int c){
e[idx]=b, ne[idx]=h[a], w[idx]=c, h[a]=idx++;
}
void dijkstra(){
memset(dist, 0x3f, sizeof dist);
priority_queue<PII, vector<PII>, greater<PII>> heap;
heap.push({0,n});
dist[n]=0;
while(heap.size()){
auto t=heap.top();
heap.pop();
int distance=t.first, ver=t.second;
if(st[ver]) continue;
st[ver]=true;
for(int i=h[ver]; i!=-1; i=ne[i]){
int j=e[i];
if(dist[j]>distance+w[i]){
dist[j] = distance+w[i];
heap.push({dist[j], j});
}
}
}
}
int dfs(int u){
if(memo[u]!=-1) return memo[u];
if(u==n) return memo[u]=1;
memo[u]=0;
for(int i=h[u]; i!=-1; i=ne[i]){
int j=e[i];
if(dist[j]<dist[u]){
memo[u]=(memo[u]+dfs(j))%mod;
}
}
return memo[u];
}
int countRestrictedPaths(int n, vector<vector<int>>& edges) {
memset(h, -1, sizeof h);
this->n=n;
for(auto e:edges){
add(e[0], e[1], e[2]), add(e[1], e[0], e[2]);
}
dijkstra();
memset(memo, -1, sizeof memo);
return dfs(1);
}
};