Pagini recente » Cod sursa (job #1660200) | Cod sursa (job #1304627) | Cod sursa (job #19368) | Cod sursa (job #2619343) | Cod sursa (job #2543312)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1505;
const int MOD = 104659;
const long double EPS = 1e-9L;
const int INF = 2000000000;
int N, M;
vector < pair <int, int> > graph[NMAX];
long double dist[NMAX];
int cnt[NMAX];
bitset <NMAX> seen;
struct Heap
{
int node;
long double cost;
Heap()
{
this->node = this->cost = 0;
}
Heap(int node, long double cost)
{
this->node = node;
this->cost = cost;
}
inline bool operator<(const Heap& other) const
{
return this->cost > other.cost;
}
};
bool eps(long double x)
{
return (x < -EPS || EPS < x);
}
priority_queue <Heap> pq;
int main()
{
ifstream fin("dmin.in");
ofstream fout("dmin.out");
fin >> N >> M;
for (int i = 1;i <= M;++i)
{
int u, v, c;
fin >> u >> v >> c;
graph[u].push_back(make_pair(v, c));
graph[v].push_back(make_pair(u, c));
}
for (int i = 2;i <= N;++i)
dist[i] = INF;
cnt[1] = 1;
pq.push(Heap(1, 0));
while (!pq.empty())
{
int node = pq.top().node;
long double cost = pq.top().cost;
pq.pop();
if (seen[node] == 0)
{
seen[node] = 1;
for (auto& i : graph[node])
{
if (!eps(dist[i.first] - (dist[node] + log(i.second))))
cnt[i.first] = (cnt[i.first] + cnt[node]) % MOD;
else if (dist[i.first] > dist[node] + log(i.second))
{
cnt[i.first] = cnt[node];
dist[i.first] = dist[node] + log(i.second);
pq.push(Heap(i.first, dist[i.first]));
}
}
}
}
for (int i = 2;i <= N;++i)
fout << cnt[i] << " ";
fin.close();
fout.close();
return 0;
}