Pagini recente » Cod sursa (job #768588) | Cod sursa (job #3253601)
#include <bits/stdc++.h>
#define P 104659
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
///dmin
///restmare
const double EPS = 1e-9;
double dabs(double x)
{
return x > 0 ? x : -x;
}
struct Doi
{
int x;
double cost;
bool operator<(const Doi e) const
{
return cost > e.cost;
}
};
vector<Doi> v[1505];
double d[1505];
int sol[1505], n, m;
priority_queue<Doi> q;
bitset<1505> viz;
void Citire()
{
int i, x, y;
double c;
fin >> n >> m;
for(i=1; i<=m; i++)
{
fin >> x >> y >> c;
c = log2(c);
v[x].push_back({y, c});
v[y].push_back({x, c});
}
}
void Dijkstra()
{
int i, k;
double cost;
for(i=1; i<=n; i++)
d[i] = 1e9;
d[1] = 0;
sol[1] = 1;
q.push({1, 0});
while(!q.empty())
{
k = q.top().x;
q.pop();
if(viz[k] == 0)
{
viz[k] = 1;
for (Doi e : v[k])
{
i = e.x;
cost = e.cost;
if(d[i] - (d[k] + cost) > EPS)
{
d[i] = d[k] + cost;
sol[i] = sol[k];
q.push({i, d[i]});
}
else if(dabs(d[k] + cost - d[i]) < EPS)
sol[i] = (sol[i] + sol[k]) % P;
}
}
}
for(i=2;i<=n;i++)
fout << sol[i] << " ";
}
int main()
{
ios_base::sync_with_stdio(0);
fin.tie(0);
fout.tie(0);
Citire();
Dijkstra();
fin.close();
fout.close();
return 0;
}