Pagini recente » Cod sursa (job #223512) | Cod sursa (job #2045933) | Cod sursa (job #1323428) | Cod sursa (job #620974) | Cod sursa (job #1388668)
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "dmin";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;
const int INF = (1LL << 30) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const lld NMAX = 1500 + 5;
const lld MOD = 104659;
lld N, M;
vector<PLL> V[NMAX];
lld sol[NMAX];
lld D[NMAX];
bitset<NMAX> viz;
priority_queue<PLL, vector<PLL>, greater<PLL> > PQ;
void dijkstra(lld x) {
lld i, y, z;
for(i = 2; i <= N; i++)
D[i] = LINF;
D[x] = 0;
PQ.push(make_pair(D[x], x));
sol[x] = 1;
while(!PQ.empty()) {
x = PQ.top().second;
PQ.pop();
if(viz[x])
continue;
viz[x] = 1;
for(auto nod : V[x]) {
y = nod.first;
z = nod.second;
if(D[x] + z < D[y]) {
D[y] = D[x] + z;
PQ.push(make_pair(D[y], y));
sol[y] = 0;
}
if(D[x] + z == D[y])
sol[y] = (sol[y] + sol[x]) % MOD;
}
}
}
int main() {
lld i, x, y, z;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
scanf("%lld%lld", &N, &M);
while(M--) {
scanf("%lld%lld%lld", &x, &y, &z);
z = 1.0 * log(z) * 1LL * 10000000000000000.0;
V[x].push_back(make_pair(y, z));
V[y].push_back(make_pair(x, z));
}
dijkstra(1);
for(i = 2; i <= N; i++)
printf("%lld ", sol[i]);
return 0;
}