# Cod sursa(job #2344020)

Utilizator Data 14 februarie 2019 17:48:40 Drumuri minime 100 cpp-64 done Arhiva de probleme 1.63 kb
``````#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
#define Nmax 1505
#define INF 0x3f3f3f3f
#define MOD 104659

using namespace std;

ifstream f("dmin.in");
ofstream g("dmin.out");

double EPS=1e-8;
double d[Nmax];
int cnt[Nmax];
bool in[Nmax];
struct cmp{
bool operator()(int x, int y)
{
return d[x]-d[y]>EPS;
}
};

int n, m;
vector <pair <int, long double> > v[Nmax];
priority_queue <int, vector <int>, cmp> Q;

void dijkstra()
{
for (int i = 2; i <= n; i++)
d[i]=INF;

cnt[1]=1;
d[1]=0;
in[1]=1;
Q.push(1);
while(!Q.empty())
{
int x=Q.top();
in[x]=0;
Q.pop();
for (int i = 0; i < v[x].size(); i++)
{
int y=v[x][i].first;
double c=v[x][i].second;
if(d[y]-d[x]-c>EPS)
{
cnt[y]=cnt[x]%MOD;
d[y]=d[x]+c;
if(in[y] == 0)
{
Q.push(y);
in[y]=1;
}
}
else
{
if(abs(d[y]-d[x]-c)<EPS)
{
cnt[y]+=cnt[x];
cnt[y]%=MOD;
}
}
}
}

for (int i = 2; i <= n; i++) g << cnt[i] << " " ;

}

int main()
{
f >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y;
long double c;
f >> x >> y >> c;
v[x].push_back({y, log2(1.0*c)});
v[y].push_back({x, log2(1.0*c)});
}

dijkstra();

return 0;
}
``````