Cod sursa(job #1489514)

Utilizator DacianBocea Dacian Dacian Data 21 septembrie 2015 13:21:34
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>

const int max = 50001;
int d[max],n,m,a,t,b,c,e;
bool k=true;

int main(){
	std::ifstream f("distante.in");
	std::ofstream of("distante.out");
	f >> t;
	for (int i = 0; i < t; ++i){
		f >> n >> m >> a;
		for (int j = 1; j <= n; ++j) f >> d[j];
		if (d[a] != 0) k = false;
		for (int j = 0; j < m; ++j){
			f >> b >> e >> c;
			if (d[b] + c < d[e] || d[e] + c < d[b]) k = false;
		}
		if (k) of << "DA\n";
		else of << "NU\n";
	}
	return 0;
}