Pagini recente » Cod sursa (job #2819954) | Cod sursa (job #3122952) | Cod sursa (job #2582843) | Cod sursa (job #2576572) | Cod sursa (job #2594769)
#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream cin("dmin.in");
ofstream cout("dmin.out");
priority_queue<pair <double,int>,vector <pair < double,int>>,greater<pair < double,int>>> q;
int x,y;
const double eps=0.00000000001;
double z;
int n,m;
pair<double,int> d[50005];
vector<pair <int ,double>> v[250005];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++){
d[i].first=0x3f3f3f3f;
}
for(int i=1;i<=m;i++){
cin>>x>>y>>z;
v[x].push_back({y,log10(z)});
v[y].push_back({x,log10(z)});
}
d[1].first=0;
d[1].second=1;
q.push({0,1});
while(!q.empty()){
int nod=q.top().second;
q.pop();
for(auto x: v[nod]){
if(d[x.first].first-(d[nod].first+x.second)>eps){
d[x.first].first=d[nod].first+x.second;
d[x.first].second=d[nod].second%104659;
d[x.first].second%=104659;
q.push({d[x.first].first,x.first});
}
else{
if(fabs(d[x.first].first-(d[nod].first+x.second))<=eps ){
d[x.first].second+=d[nod].second%104659;
d[x.first].second%=104659;
}
}
}
}
for(int i=2;i<=n;i++){
cout<<d[i].second<<" ";
}
return 0;
}