Pagini recente » Cod sursa (job #1211906) | Cod sursa (job #3147606) | Cod sursa (job #3000285) | Cod sursa (job #2637434) | Cod sursa (job #1722621)
#include <bits/stdc++.h>
#define MOD 104659
#define maxN 1505
#define EPS 1e-8
#define INF (1<<30)
using namespace std;
int n,m,i,j,x,y;
double z;
double dist[maxN];
int nmb[maxN];
vector<pair<int,double> >v[maxN];
struct cmp
{
bool operator() (pair<int,double> x ,pair<int,double> y)
{
return x.second>y.second;
}
};
priority_queue<pair<int,double> ,vector<pair<int,double> >, cmp>heap;
int main()
{
ifstream f("dmin.in");
ofstream g("dmin.out");
f>>n>>m;
for(i=1;i<=m;i++)
{
f>>x>>y>>z;
v[x].push_back(make_pair(y,log10(z)));
v[y].push_back(make_pair(x,log10(z)));
}
dist[1]=0;
nmb[1]=1;
for(i=2;i<=n;i++)
dist[i]=INF;
int node;
double cost;
heap.push(make_pair(1,0));
while(!heap.empty())
{
node=heap.top().first;
cost=heap.top().second;
heap.pop();
for(vector<pair<int,double> >::iterator it=v[node].begin();it!=v[node].end();it++)
if(dist[it->first]-EPS >= it->second+cost)
{
dist[it->first]=cost+it->second;
nmb[it->first]=nmb[node];
heap.push(make_pair(it->first,dist[it->first]));
nmb[it->first]%=MOD;
}
else if(fabs(it->second+cost - dist[it->first])<=EPS)
{
nmb[it->first]+=nmb[node];
nmb[it->first]%=MOD;
}
}
for(i=2;i<=n;i++)
g<<nmb[i]<<" ";
return 0;
}