Pagini recente » Cod sursa (job #2690249) | Cod sursa (job #490012) | Cod sursa (job #190239) | Cod sursa (job #1635535) | Cod sursa (job #1388843)
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <cstring>
using namespace std;
ifstream in ("dmin.in");
ofstream out ("dmin.out");
const int MAXN = 1500 + 10;
const long double EPS = 1e-10;
const long double INF = 1e20;
const int MOD = 104659;
typedef pair <int, long double> PID;
int N;
vector <PID> Graf[MAXN];
long double Best[MAXN];
int Ans[MAXN];
struct comp
{
inline bool operator () (const int &A, const int &B) const
{
return (Best[A] - Best[B]) >= EPS;
}
};
//priority_queue <int, vector <int>, comp> Q;
set <int, comp> Q;
void Dijkstra ()
{
int nod;
int i;
vector <PID> :: iterator it;
for (i = 1; i <= N; i ++)
Best[i] = INF;
//Q.push (1);
Q.insert (1);
Ans[1] = 1;
Best[1] = 0;
while (!Q.empty ()){
//nod = Q.top ();
//Q.pop ();
nod = *(Q.begin ());
Q.erase (Q.begin ());
for (it = Graf[nod].begin (); it != Graf[nod].end (); ++ it){
const int next = (it -> first);
const long double cost = (it -> second);
if (abs (Best[nod] + cost - Best[next]) <= EPS){
Ans[next] = (Ans[nod] + Ans[next]) % MOD;
}
else
if (Best[nod] + cost - Best[next] < -EPS){
Best[next] = Best[nod] + cost;
Ans[next] = Ans[nod];
//Q.push (next);
Q.erase (next);
Q.insert (next);
}
}
}
}
int main()
{
int M, a, b, c;
int i;
long double new_cost;
in >> N >> M;
for (i = 1; i <= M; i ++){
in >> a >> b >> c;
new_cost = log (c);
Graf[a].push_back (make_pair (b, new_cost));
Graf[b].push_back (make_pair (a, new_cost));
}
Dijkstra ();
for (i = 2; i <= N; i ++)
out << Ans[i] << " ";
return 0;
}