Pagini recente » Cod sursa (job #390062) | Cod sursa (job #1871913) | Cod sursa (job #680756) | Cod sursa (job #2545644) | Cod sursa (job #920983)
Cod sursa(job #920983)
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#define INF 9999999.0
#define pb push_back
#define mkp make_pair
#define nxt (*it).first
#define cst (*it).second
#define FOR(i,a,b)\
for(int i=a; i<=b; ++i)
#define ALL(g)\
for(typeof(g.begin()) it=g.begin(); it!=g.end(); ++it)
#define infile "dmin.in"
#define outfile "dmin.out"
#define nMax 1505
#define MOD 104659
#define EPS 0.000000001
using namespace std;
priority_queue < pair < double, int > > PQ;
vector < pair < int, double > > v[nMax];
double D[nMax];
int NR[nMax];
bitset < nMax > inQueue;
int N, M;
void read(){
freopen(infile, "r", stdin);
scanf("%d %d", &N, &M);
int x, y, c;
while(M--){
scanf("%d %d %d", &x, &y, &c);
v[x].pb(mkp(y,log(c)));
v[y].pb(mkp(x,log(c)));
}
fclose(stdin);
}
void Dijkstra(){
FOR(i,2,N)
D[i] = INF;
NR[1] = 1;
PQ.push(mkp(0.0, 1));
inQueue[1] = true;
while(!PQ.empty()){
double dx = -PQ.top().first;
int x = PQ.top().second;
PQ.pop();
inQueue[x] = false;
ALL(v[x])
if(D[nxt] - dx - cst > EPS){
D[nxt] = dx + cst;
NR[nxt] = NR[x];
if(!inQueue[nxt]){
PQ.push(mkp(-D[nxt], nxt));
inQueue[nxt] = true;
}
}
else if(abs(D[nxt] - dx - cst) < EPS)
NR[nxt] = (0LL + NR[nxt] + NR[x]) % MOD;
}
}
void print(){
freopen(outfile, "w", stdout);
FOR(i,2,N)
printf("%d ", NR[i]);
fclose(stdout);
}
int main(){
read();
Dijkstra();
print();
return 0;
}