Mai intai trebuie sa te autentifici.

Cod sursa(job #888568)

Utilizator StanAndreiAndrei Stan StanAndrei Data 24 februarie 2013 11:40:50
Problema Ubuntzei Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>

using namespace std;

ifstream f1("ubuntzei.in");
ofstream f2("ubuntzei.out");

int a[2000][2000],n,m,k,c;

void citeste()
{
	int i,j;
	f1>>n>>m;
	int c;
	f1>>k;
	if(k!=0)
	for(i=1;i<=k;i++)
		f1>>c;
	
	int x,y,z;
	for(i=1;i<=m;i++)
	{
		f1>>x>>y>>z;
		a[x][y]=z;
		a[y][x]=z;
	}
}

void solve()
{
	int i,j;
	for(int k = 1; k <= n; k++)
		for(i = 1; i <= n; i++)
			for(j = 1; j <= n; j++) 
				if(a[i][k] && a[k][j] && i != j && (a[i][j] > a[i][k] + a[k][j] || !a[i][j]))
					a[i][j] = a[i][k] + a[k][j];
	f2<<a[1][n];
}

int main()
{
	citeste();
	solve();
	
	f1.close();
	f2.close();
	return 0;
}