Pagini recente » Cod sursa (job #1681628) | Cod sursa (job #200474) | Cod sursa (job #1291626) | Cod sursa (job #724968) | Cod sursa (job #3207660)
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
#define N 1501
#define M 2500
#define mod 104659
#define inf 999999999
ifstream fin("dmin.in");
ofstream fout("dmin.out");
int n, m, x, y, k;
double cst;
int t[3][2*M], start[N], nr[N];
bool viz[N];
double cost[N];
queue <int> c;
void ford()
{
int om, man;
c.push(1);
viz[1] = 1;
nr[1] = 1;
while( !c.empty() )
{
om = c.front();
man = start[om];
viz[om] = 0;
while(man)
{
if(cost[om] + t[2][man] < cost[t[0][man]] )
{
cost[t[0][man]] = cost[om] + t[2][man];
nr[t[0][man]] = nr[om] % mod;
if( !viz[t[0][man]])
{
viz[t[0][man]] = 1;
c.push(t[0][man]);
}
}
else
if(cost[om] + t[2][man] == cost[t[0][man]])
nr[t[0][man]] = (nr[t[0][man]] + nr[om]) % mod;
man = t[1][man];
}
c.pop();
}
}
int main()
{
fin >> n >> m;
while(fin >> x >> y >> cst)
{
k++;
t[0][k] = y;
t[1][k] = start[x];
start[x] = k;
k++;
t[0][k] = x;
t[1][k] = start[y];
start[y] = k;
t[2][k] = t[2][k-1] = cst;
}
for(int i=2; i<=n; i++)
cost[i] = inf;
cost[1] = 0;
ford();
for(int i=2; i<=n; i++)
fout << nr[i] % mod << " ";
return 0;
}