Pagini recente » Cod sursa (job #2269871) | Cod sursa (job #1742232) | Cod sursa (job #2271921) | Cod sursa (job #132058) | Cod sursa (job #2978635)
#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#define ll long long
#define pb push_back
#define bg begin
#define en end
#define x first
#define y second
using namespace std;
ifstream in("dmin.in");
ofstream out("dmin.out");
const int NMAX = 1505;
const int MOD = 104659;
const double INF = 1e9 + 5;
const double err = 1e-6;
const char nl = '\n';
int n, m, ans[NMAX], inq[NMAX];
double dist[NMAX];
struct pii{
int x;
double y;
bool operator < (const pii &aux) const
{
return y > aux.y;
}
};
vector<pii> v[NMAX];
priority_queue<pii> pq;
void solve(){
for(int i = 1; i <= n; ++i)
dist[i] = INF;
dist[1] = 0, inq[1] = 1, ans[1] = 1;
pq.push({1, 0});
while(!pq.empty()){
int cur_node = pq.top().first;
pq.pop();
inq[cur_node] = 0;
for(auto neigh: v[cur_node]){
if(dist[neigh.x] - dist[cur_node] - neigh.y > err){
dist[neigh.x] = dist[cur_node] + neigh.y;
ans[neigh.x] = 0;
if(!inq[neigh.x]){
inq[neigh.x] = 1;
pq.push({neigh.x, dist[neigh.x]});
}
}
if(abs(dist[neigh.x] - dist[cur_node] - neigh.y) < err)
ans[neigh.x] += ans[cur_node] % MOD;
}
}
for(int i = 1; i <= n; ++i)
out << ans[i] << ' ';
out << nl;
}
int main()
{
in >> n >> m;
for(int i = 1; i <= m; ++i){
int a, b;
double c;
in >> a >> b >> c;
c = log(c);
v[a].pb({b, c});
v[b].pb({a, c});
}
solve();
return 0;
}