Pagini recente » Cod sursa (job #2736952) | Cod sursa (job #2740630) | Cod sursa (job #1961935) | Cod sursa (job #2140677) | Cod sursa (job #2978648)
#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
#define int ll
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().x;
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[neigh.x] + ans[cur_node]) % MOD;
}
}
}
for(int i = 2; i <= n; ++i)
out << ans[i] << ' ';
out << nl;
}
signed 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;
}