Pagini recente » Cod sursa (job #18806) | Cod sursa (job #1857222) | Cod sursa (job #2613303) | Cod sursa (job #2260389) | Cod sursa (job #2923468)
#include <bits/stdc++.h>
using namespace std;
ifstream r("distante.in");
ofstream w("distante.out");
int dist[50003];
int n, m, s;
int main()
{
int t;
r>>t;
while(t--)
{
int x, y, cost;
bool ok=1;
r>>n>>m>>s;
for(int i=1; i<=n; i++){
r>>dist[i];
}
if(dist[s]!=0){
ok=0;
}
for(int i=1; i<=m; i++)
{
r>>x>>y>>cost;
if(dist[x]+cost<dist[y] || dist[y]+cost<dist[x]){
ok=0;
}
}
if(ok==1){
w<<"DA"<<"\n";
}
else{
w<<"NU"<<"\n";
}
}
return 0;
}