# Cod sursa(job #42865)

Utilizator Data 29 martie 2007 16:31:54 Drumuri minime 10 cpp done Arhiva de probleme 1.49 kb
``````#include<fstream.h>
#include<math.h>
#define _DIM_ 1501
#define modulo 104659
#define eps 0.00001

double abs(double x)
{
if(x>0)return x;
return -x;
}

ifstream f("dmin.in");
ofstream g("dmin.out");
typedef struct _lista
{
int x;
double c;
_lista *urm;
}*Lista;
typedef struct _nod
{
Lista l;
}Nod;
Nod V[_DIM_];
double c[_DIM_];
long mod[_DIM_];
{
Lista nou=new _lista;
nou->x=y;nou->c=cost;
nou->urm=V[x].l;
V[x].l=nou;
}
void citire()
{
int i,cost,x,y;
f>>n>>m;
for(i=1;i<=m;i++)
}
void getmin(int p,int u)
{
int i,aux;
int minpoz=p;
for(i=p+1;i<=u;i++)
}
void dijkstra(int k)
{
Lista i;
v[k]=1;c[k]=0;
while(p<=u)
{
getmin(p,u);
for(i=V[k].l;i;i=i->urm)
if(!v[i->x])
c[i->x]=c[k]+log(i->c);

else
{
if(c[i->x]>c[k]+log(i->c))
c[i->x]=c[k]+log(i->c),mod[i->x]=mod[k],mod[i->x]%=modulo;
if(abs(c[i->x]-(c[k]+log(i->c)))<eps)
mod[i->x]+=mod[k],mod[i->x]%=modulo;
}
p++;
}
}
int main()
{
int i;
citire();f.close();
mod[1]=1;
dijkstra(1);
for(i=2;i<=n;i++)
g<<mod[i]%modulo<<" ";
g.close();
return 0;
}
``````