Pagini recente » Cod sursa (job #2799993) | Cod sursa (job #2255676) | Cod sursa (job #508170) | Cod sursa (job #758315) | Cod sursa (job #2938532)
#include <fstream>
#include <queue>
#include <cmath>
#include <bitset>
#include <vector>
using namespace std;
ifstream in ("dmin.in");
ofstream out ("dmin.out");
struct str{
int nod;
double val;
bool operator < (const str &aux) const
{
return val > aux.val;
}
};
/// ideea e ca daca logaritmez, stiu ca ln(a * b) = ln a + ln b deci merge un dijkstra banal
const int max_size = 15e2 + 1, mod = 104659;
const double INF = 1e9 + 1;
long long dp[max_size], n;
double d[max_size];
vector <str> mc[max_size];
priority_queue <str> pq;
bitset <max_size> inq;
void djk ()
{
for (int i = 1; i <= n; i++)
{
d[i] = INF;
}
d[1] = 0;
dp[1] = 1;
inq[1] = 1;
pq.push({1, 0});
while (!pq.empty())
{
int nod = pq.top().nod;
pq.pop();
inq[nod] = 0;
for (auto f : mc[nod])
{
if (d[nod] + f.val < d[f.nod])
{
d[f.nod] = d[nod] + f.val;
dp[f.nod] = 0;
if (!inq[f.nod])
{
inq[f.nod] = 1;
pq.push({f.nod, d[f.nod]});
}
}
if (d[nod] + f.val == d[f.nod])
{
dp[f.nod] = (dp[f.nod] + dp[nod]) % mod;
}
}
}
}
int main ()
{
int m;
in >> n >> m;
while (m--)
{
int x, y;
double z;
in >> x >> y >> z;
z = log(z);
mc[x].push_back({y, z});
//mc[y].push_back({x, z});
}
djk();
for (int i = 2; i <= n; i++)
{
out << dp[i] << " ";
}
in.close();
out.close();
return 0;
}