Pagini recente » Cod sursa (job #2074720) | Cod sursa (job #2854406) | Cod sursa (job #1053129) | Cod sursa (job #648043) | Cod sursa (job #1589232)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#define INF 1 << 29
#define NMAX 50002
using namespace std;
struct punct
{
int nod,cost;
}p,v;
ifstream in("distante.in");
ofstream out("distante.out");
int n,m,x,y,s,cost,t,d[NMAX];
bool verf[NMAX];
bool dijkstra()
{
bool gasit = false;
if(d[s]!=0) return false;
for(int i=1;i<=m;i++)
{
in >> x >> y >> cost;
if(d[x]+ cost < d[y])
return false;
if(d[x]+cost == d[y]) gasit = true;
}
if(gasit) return true;
return false;
}
int main()
{
in >> t;
for(int k=0;k<t;k++)
{
in >> n >> m >> s;
for(int i=1;i<=n;i++)
{
in >> d[i];
}
if(dijkstra())
out << "DA" << "\n";
else
out << "NU" << "\n";
}
return 0;
}