Pagini recente » Cod sursa (job #398012) | Cod sursa (job #2219439) | Cod sursa (job #2732436) | Cod sursa (job #2135545) | Cod sursa (job #1563179)
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;
#define Nmax 1502
#define Mod 104659
#define inf 0x3f3f3f3f
#define eps 1e-10
ifstream fin ( "dmin.in" );
ofstream fout ( "dmin.out" );
int N, M, Aport[Nmax];
double Dist[Nmax];
vector < pair < int, double > > G[Nmax];
bitset < Nmax > inQ;
queue < int > Q;
void BellmanFord(){
for ( int i = 2; i <= N; ++i )
Dist[i] = inf;
Aport[1] = 1;
Q.push ( 1 );
inQ[1] = 1;
vector < pair < int, double > > :: iterator it;
while ( !Q.empty() ){
int nod = Q.front();
Q.pop();
inQ[nod] = 0;
for ( it = G[nod].begin(); it != G[nod].end(); ++it ){
if ( Dist[it->first] - (Dist[nod] + it->second) >= eps ){
Dist[it->first] = Dist[nod] + it->second;
Aport[it->first] = Aport[nod];
if ( !inQ[it->first] ){
Q.push ( it->first );
inQ[it->first] = 1;
}
}
else if ( abs ( (Dist[nod] + it->second) - Dist[it->first] ) < eps ){
Aport[it->first] += Aport[nod];
Aport[it->first] %= Mod;
}
}
}
}
int main(){
int x, y, c;
fin >> N >> M;
while ( M-- ){
fin >> x >> y >> c;
G[x].push_back ( make_pair ( y, log10(c) ) );
G[y].push_back ( make_pair ( x, log10(c) ) );
}
BellmanFord();
for ( int i = 2; i <= N; ++i )
fout << Aport[i] << " ";
return 0;
}