Pagini recente » Cod sursa (job #2889220) | Cod sursa (job #1183962) | Cod sursa (job #58426) | Cod sursa (job #2570039)
#include <bits/stdc++.h>
#define p64 pair <long long,long>
#define mp make_pair
#define M 104659
#define M2 1000000007
using namespace std;
ifstream f("dmin.in");
ofstream g("dmin.out");
long long n,m,cost[1<<11],dp[1<<11];
vector <p64> v[1<<11];
set <p64> heap;
int main()
{ f>>n>>m;
for(int x,y,c; f>>x>>y>>c;)
{ v[x].push_back(mp(y,c));
v[y].push_back(mp(x,c));
}
for(int i=1; i<=n; i++)
cost[i]=1<<30;
cost[1]=dp[1]=1;
heap.insert(mp(1,1));
while(!heap.empty())
{ int nod=heap.begin()->second;
heap.erase(heap.begin());
vector <p64> :: iterator it;
for(it=v[nod].begin(); it!=v[nod].end(); it++)
{ long long c=(cost[nod]*(it->second))%M2;
if(c<cost[it->first])
{ cost[it->first]=c;
dp[it->first]=dp[nod];
heap.insert(mp(c,it->first));
}
else
if(c==cost[it->first])
dp[it->first]=(dp[it->first]+dp[nod])%M;
}
}
for(int i=2; i<=n; i++)
g<<dp[i]<<' ';
g.close(); return 0;
}