Pagini recente » Cod sursa (job #1790984) | Cod sursa (job #352887) | Cod sursa (job #1792419) | Cod sursa (job #1959942) | Cod sursa (job #1052232)
#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;
}