Pagini recente » Cod sursa (job #771883) | Cod sursa (job #2018254) | Cod sursa (job #2107949) | Cod sursa (job #382058) | Cod sursa (job #1052236)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("distante.in");
ofstream out("distante.out");
int T, N, M, S, cost[50010];
int main()
{
int x, y, c, i, j, ok;
in >> T;
for(i = 1; i <= T; i++){
in >> N >> M >> S;
for(j = 1 ; j <= N; j++){
in >> cost[j];
}
ok = 1;
for(j = 1; j <= M; j++){
in >> x >> y >> c;
if(cost[x] + c < cost[y]){
ok = 0;
}
if(cost[y] + c < cost[x]){
ok = 0;
}
}
if(cost[S]){
ok = 0;
}
if(ok == 0){
out << "NU\n";
}else{
out << "DA\n";
}
}
return 0;
}