Cod sursa(job #526096)

Utilizator dornescuvladVlad Eugen Dornescu dornescuvlad Data 27 ianuarie 2011 13:19:37
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

const char iname[] = "distante.in";
const char oname[] = "distante.out";

ifstream fin(iname);
ofstream fout(oname);

int t, n, i, j, m, s, okey;
int D[50005];
int x, y, c, k;
vector<pair <int, int> >Gr[50005];

int main()
{
	fin >> t;
	for(i = 1; i <= t; i ++)
	{	
		fin >> n >> m >> s;
		for(j = 1; j <= n; j ++)
			fin >> D[j];
		for(j = 1; j <= m; j ++)
		{
			fin >> x >> y >> c;
			Gr[x].push_back(make_pair(y, c));
			Gr[y].push_back(make_pair(x, c));
		}
		okey = 1;
		for(j = 1; j <= n; j ++)
		{	
			if(j == s)
			{
				okey = 1;
				continue;
			}
			if(okey == 0)
				break;
			okey = 0;
			for(k = 0; k < Gr[j].size(); k ++)
				if(D[Gr[j][k].first] + Gr[j][k].second == D[j])
					okey = 1;
			if(okey == 0)
				break;
		}
	
		if(okey == 1)
			fout << "DA\n";
		else
			fout << "NU\n";
	}
		return 0;
}