Pagini recente » Cod sursa (job #957385) | Cod sursa (job #108096) | Cod sursa (job #866607) | Cod sursa (job #1468671) | Cod sursa (job #1389537)
#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;
typedef pair<int, double> PID;
typedef pair<double, int> PDI;
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 int NMAX = 1500 + 5;
const int MOD = 104659;
int N, M;
vector<PID> V[NMAX];
int sol[NMAX];
double D[NMAX];
bitset<NMAX> viz;
deque<int> Q;
void bf(int x) {
int i, y;
double z;
for(i = 2; i <= N; i++)
D[i] = INF;
sol[x] = 1;
Q.push_back(x);
viz[x] = 1;
while(!Q.empty()) {
x = Q.front();
Q.pop_front();
viz[x] = 0;
for(auto nod : V[x]) {
y = nod.first;
z = nod.second;
if(D[x] + z < D[y]) {
D[y] = D[x] + z;
sol[y] = 0;
if(!viz[y]) {
Q.push_back(y);
viz[y] = 1;
}
}
if(D[x] + z == D[y])
sol[y] = (sol[y] + sol[x]) % MOD;
}
}
}
int main() {
int i, x, y, z;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
scanf("%d%d", &N, &M);
while(M--) {
scanf("%d%d%d", &x, &y, &z);
V[x].push_back(make_pair(y, log2(z)));
V[y].push_back(make_pair(x, log2(z)));
}
bf(1);
for(i = 2; i <= N; i++)
printf("%d ", sol[i]);
return 0;
}