Cod sursa(job #961757)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 12 iunie 2013 20:06:50
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#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, M, S, i, j, a, b, c, oke;
int d[50004];
int main(){
	fin >> T;
	while (T--){
		fin >> N >> M >> S;
		oke = 1;
		for (i = 1; i <= N; ++i) fin >> d[i];
		if (d[S] != 0) oke = 0;
		for (i = 1; i <= M && oke; ++i){
			fin >> a >> b >> c;
			if (d[a] > d[b] + c || d[b] > d[a] + c) oke = 0;
		}
		if (oke) fout << "DA\n";
		else
			fout << "NU\n";
	}
	return 0;
}