Cod sursa(job #2439056)

Utilizator 0SiSBesliu Radu-Stefan 0SiS Data 14 iulie 2019 18:44:11
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>

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

int T, n, m, start, x, y, cost, d[50001];

int main()
{
	f >> T;
	for (int i = 1; i <= T; ++i) {
		bool ok = 1;
		f >> n >> m >> start;
		for (int j = 1; j <= n; ++j) {
			f >> d[j];
		}
		if (d[start]) {
			ok = 0;
		}
		for (int j = 1; j <= m; ++j) {
			f >> x >> y >> cost;
			if (d[x] + cost < d[y] || d[y] + cost < d[x]) {
				ok = 0;
			}
		}
		if (ok) {
			g << "DA\n";
		}
		else {
			g << "NU\n";
		}
	}
}