Pagini recente » Cod sursa (job #1614996) | Cod sursa (job #1824203) | Cod sursa (job #259284) | Cod sursa (job #2198711) | Cod sursa (job #1537446)
#include<fstream>
#include<vector>
#include<cmath>
#define mod 104659
#define inf 2000000000
#define lgc 0.00000001
using namespace std;
vector <pair <int, float> > L[1502];
float z, D[1502], cost;
int n, m, x, y, i, nr[1502], p[1502], h[1502], nod, p1, s, nrh, vecin;
ifstream in("dmin.in");
ofstream out("dmin.out");
int main()
{
in>>n>>m;
for(i=1; i<=m; i++)
{
in>>x>>y>>z;
L[x].push_back(make_pair(y, log(z)));
L[y].push_back(make_pair(x, log(z)));
}
for(i=2; i<=n; i++)
D[i]=inf;
nr[1]=1;
h[++nrh]=1;
p[1]=nrh;
while(nrh!=0)
{
nod=h[1];
h[1]=h[nrh];
nrh--;
p1=1;
s=2;
while(s<=nrh)
{
if(s+1<=nrh && D[h[s+1]]<D[h[s]])
s++;
if(D[h[s]]<D[h[p1]])
{
swap(h[s], h[p1]);
p[h[s]]=s;
p[h[p1]]=p1;
p1=s;
s*=2;
}
else
break;
}
for(i=0; i<L[nod].size(); i++)
{
vecin=L[nod][i].first;
cost=L[nod][i].second;
if(D[vecin]-(D[nod]+cost)>lgc)
{
nr[vecin]=nr[nod];
D[vecin]=D[nod]+cost;
if(p[vecin]!=0)
{
s=p[vecin];
p1=s/2;
}
else
{
h[++nrh]=vecin;
p[vecin]=nrh;
s=nrh;
p1=s/2;
}
while(p1!=0 && D[h[s]]<D[h[p1]])
{
swap(h[s], h[p1]);
p[h[s]]=s;
p[h[p1]]=p1;
s=p1;
p1/=2;
}
}
else
if(D[vecin]-(D[nod]+cost)<lgc && D[vecin]-(D[nod]+cost)>-lgc)
nr[vecin]=(nr[vecin]+nr[nod])%104659;
}
}
for(i=2; i<=n; i++)
out<<nr[i]<<" ";
return 0;
}