Cod sursa(job #1336572)

Utilizator IulianBoboUAIC Boboc Iulian IulianBobo Data 7 februarie 2015 22:37:33
Problema Distante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;

#define MAX_N 50001
#define MAX_M 100001
#define INF 1<<30

int t, n, m,s,k;
int distBr[MAX_N];
int dist[MAX_N], h[MAX_N], poz[MAX_N];

ifstream f("distante.in");
ofstream g("distante.out");

vector<pair<int, int>> el[MAX_N];

int Q[MAX_N];
bool InQueue[MAX_N];

void readData()
{
	int a, b, c;
	f >> n >> m >> s;
	for (int i = 1; i <= n; ++i)
	{
		f >> distBr[i];
		InQueue[i] = false;
	}
	for (int i = 1; i <= m; i++)
	{
		f >> a >> b >> c;
		el[a].push_back(make_pair(b,c));
		el[b].push_back(make_pair(a, c));
	}
}

void compute()
{
	int i;
	bool ok = true;
	for (i = 1; i <= n; i++)
	{
		dist[i] = INF;
	}

	if (distBr[s] != 0) ok = false;

	if (ok)
	{
		for (i = 1; i <= n && ok; i++)
		{
			for (vector<pair<int, int>>::iterator it = el[i].begin(); it != el[i].end() && ok; it++)
			{
				if (distBr[i] + it->second < distBr[it->first]) ok = 0;
			}
		}
	}

	if (!ok) g << "NU\n";
	else g << "DA\n";
}

int main()
{
	int i;
	f >> t;
	for (i = 1; i <= t; ++i)
	{
		readData();
		compute();
	}
	f.close();
	g.close();
	return 0;
}