Pagini recente » Cod sursa (job #1878830) | Cod sursa (job #1568226) | Cod sursa (job #1175528) | Cod sursa (job #52724) | Cod sursa (job #1522144)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("dmin.in");
ofstream fout ("dmin.out");
const int MOD = 104659;
const int MAX = 1505;
const int INF = 1e9;
const double eps = 1e-6;
set < pair <double,int> > T;
vector < pair <double,int> > G[MAX];
struct fac{
int c,a;
double d;
}D[MAX];
inline int mod(double x){
return max(x,-x);
}
inline void solve()
{
int nod,ok;
double cost;
D[1].a = 1;
D[1].d = 1;
T.insert({0,1});
while(!T.empty()){
cost = (*T.begin()).first;
nod = (*T.begin()).second;
T.erase(*T.begin());
for(int i = 0; i < G[nod].size(); i++){
if(D[G[nod][i].second].d < D[nod].d*G[nod][i].first){
D[G[nod][i].second].d = D[nod].d*G[nod][i].first;
D[G[nod][i].second].c = nod;
D[G[nod][i].second].a = D[nod].a;
T.insert({D[G[nod][i].second].d,G[nod][i].second});
} else if(mod(D[G[nod][i].second].d - D[nod].d*G[nod][i].first) < eps){
if(D[G[nod][i].second].c != nod)
D[G[nod][i].second].a += D[nod].a;
}
}
}
}
int main()
{
int n,m,x,y,c;
fin >> n >> m;
for(int i = 1; i <= m; i++){
fin >> x >> y >> c;
G[x].push_back({log(c),y});
G[y].push_back({log(c),x});
}
for(int i = 2; i <= n; i++)
D[i].d = INF;
solve();
for(int i = 2; i <= n; i++)
fout << D[i].a << " ";
return 0;
}