Pagini recente » Cod sursa (job #1918866) | Cod sursa (job #267059) | Cod sursa (job #118339) | Cod sursa (job #858688) | Cod sursa (job #2594832)
#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.0000000001;
int z;
int n,m;
pair<double,int> d[100005];
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;
double idk=q.top().first;
q.pop();
if ( idk-eps>d[nod].first)
continue;
for(auto x: v[nod]){
if(d[x.first].first-eps>d[nod].first+x.second){
d[x.first].first=d[nod].first+x.second;
d[x.first].second=d[nod].second;
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;
d[x.first].second%=104659;
}
}
}
}
for(int i=2;i<=n;i++){
cout<<d[i].second<<" ";
}
return 0;
}