Cod sursa(job #1388035)

Utilizator radudorosRadu Doros radudoros Data 15 martie 2015 00:48:09
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include<fstream>
#include<string>
using namespace std;
const int nmax = 50001;
int d[50001];



int main()
{
	ifstream fin("distante.in");
	ofstream fout("distante.out");
	int t;
	fin >> t;
	for (; t; t--)
	{
		int n, m, s;
		fin >> n >> m >> s;
		for (int i = 1; i <= n; i++)
		{
			fin >> d[i];
		}
		bool g = 0;
		for (int i = 1; i <= m; i++)
		{
			int x, y, w;
			fin >> x >> y >> w;
			if (d[x] > d[y] + w || d[y] > d[x] + w)
			{
				g = 1;
			}
		}
		(g == 0&&!d[s]) ? fout << "DA\n" : fout << "NU\n";
	}
}