Pagini recente » Cod sursa (job #2956732) | Cod sursa (job #825181) | Cod sursa (job #2981909) | Cod sursa (job #1331871) | Cod sursa (job #2950954)
#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const double eps = 1e-6;
const int maxN = 1505, inf = 0x3f3f3f3f, mod = 104659;
int n, m, ans[maxN];
double dist[maxN];
bool used[maxN];
struct heapNode {
int nod;
double cost;
bool operator < (const heapNode &other) const
{
return cost > other.cost;
}
};
vector <heapNode> G[maxN];
priority_queue <heapNode> heap;
double modul(double x)
{
if(x < 0)
x = -x;
return x;
}
void dijkstra()
{
for(int i = 1; i <= n; i++)
dist[i] = inf;
dist[1] = 0;
ans[1] = 1;
heap.push({1, 0});
while(!heap.empty())
{
heapNode curr = heap.top();
heap.pop();
if(used[curr.nod])
continue;
used[curr.nod] = 1;
for(heapNode nxt : G[curr.nod])
{
if(dist[curr.nod] + nxt.cost + eps < dist[nxt.nod])
{
dist[nxt.nod] = dist[curr.nod] + nxt.cost;
ans[nxt.nod] = 0;
heap.push({nxt.nod, dist[nxt.nod]});
}
if(modul(dist[curr.nod] + nxt.cost - dist[nxt.nod]) < eps)
ans[nxt.nod] = (ans[nxt.nod] + ans[curr.nod]) % mod;
}
}
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y, c;
fin >> x >> y >> c;
double dc = log2(c);
G[x].push_back({y, dc});
}
dijkstra();
for(int i = 2; i <= n; i++)
fout << ans[i] << ' ';
return 0;
}