Cod sursa(job #388440)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 30 ianuarie 2010 10:37:39
Problema Drumuri minime Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include<cstdio>
#include<math.h>
#define N 1501
#include<vector>
#define pb push_back
#define MOD 104659
#define INF 1<<30
#define maxx(a,b) ((a<b)?(b):(a))
using namespace std;
//vector<short int> a[N];
int z,nr[N][N];
double cost[N][N];
short int n,m,x,y;
//bool viz[N][N];
void citire()
{
	freopen("dmin.in","r",stdin);
	freopen("dmin.out","w",stdout);
	scanf("%hd%hd",&n,&m);
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; ++j)
			cost[i][j]=INF;
	for (int i=1; i<=m; ++i)
	{
		scanf("%hd%hd%d",&x,&y,&z);
		nr[x][y]=nr[y][x]=1;
		cost[x][y]=cost[y][x]=log(z);
	}
}
void rf()
{
	int i=1;
	for (int k=2; k<=n; ++k)
		for (int j=2; j<=n; ++j)
		{
			double aux=cost[i][k]+cost[k][j];
			if (cost[i][k]!=INF&&cost[k][j]!=INF)
				if (cost[i][j]>aux)
				{
					cost[i][j]=aux;
					nr[i][j]=nr[i][k];
				}
				else
					if (cost[i][j]==aux)
						nr[i][j]+=nr[i][k];
		}
	for (i=2; i<=n; ++i)
		printf("%d ",nr[1][i]);
}
int main()
{
	citire();
	rf();
	return 0;
}