Pagini recente » Cod sursa (job #1242327) | Cod sursa (job #699037) | Cod sursa (job #2967770) | Cod sursa (job #1733696) | Cod sursa (job #2439055)
#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 && ok; ++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";
}
}
}