Pagini recente » Cod sursa (job #1013857) | Cod sursa (job #3256658) | preONI 2007, Runda Finala, Clasa a 10-a | Cod sursa (job #2092892) | Cod sursa (job #1725206)
#include <bits/stdc++.h>
#define MAX 250001
using namespace std;
unsigned short int N;
unsigned int M;
unsigned short int A[MAX], B[MAX], C[MAX];
unsigned int path[MAX];
bool okay;
unsigned int i;
int main ()
{
ifstream fin ("dijkstra.in");
fin >> N >> M;
for (i=1; i<=M; i++)
fin >> A[i] >> B[i] >> C[i];
fin.close();
for (i=1; i<=M; i++)
if (A[i] == 1)
path[B[i]] = C[i];
for (i=2; i<=N; i++)
if (path[i] == 0)
path[i] = UINT_MAX;
while (okay == 0)
{
okay = 1;
for (i=1; i<=M; i++)
if (path[B[i]] > path[A[i]] + C[i])
{
path[B[i]] = path[A[i]] + C[i];
okay = 0;
}
}
ofstream fout ("dijkstra.out");
for (i=2; i<=N; i++)
if (path[i] != UINT_MAX)
fout << path[i] << ' ';
else
fout << 0 << ' ';
fout.close();
return 0;
}