Pagini recente » Cod sursa (job #1387790) | Cod sursa (job #1505212) | Cod sursa (job #741554) | Cod sursa (job #1021485) | Cod sursa (job #1589353)
#include <iostream>
#include <fstream>
#define maxN 50005
using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
int test;
bool ans;
int n,m,s,dist[maxN],x,y,c;
int main()
{
fin>>test;
while (test--)
{
ans=true;
fin>>n>>m>>s;
for (int i=1; i<=n; ++i)
fin>>dist[i];
if (dist[s]) ans=false;
for (int i=1; i<=m; ++i)
{
fin>>x>>y>>c;
if (dist[x]>dist[y]+c||dist[y]>dist[x]+c) ans=false;
}
(ans) ? fout<<"DA\n" : fout<<"NU\n";
}
return 0;
}