Pagini recente » Cod sursa (job #2804285) | Cod sursa (job #932734) | Cod sursa (job #2319754) | Cod sursa (job #98234) | Cod sursa (job #1075105)
#include<fstream>
#include<vector>
using namespace std;
ifstream f("distante.in");
ofstream g("distante.out");
struct muchie {int x,y,c;} G[100005];
int t,k,m,n,s,d[50005];
bool ap[50005];
void rez()
{
int x,y,c,i;
bool ok;
f>>n>>m>>s;
for (i=1;i<=n;++i) f>>d[i];
k=0, ap[s]=true;
for (i=1;i<=m;++i)
{
f>>x>>y>>c;
G[++k].x=x, G[k].y=y, G[k].c=c;
if (x!=y) G[++k].x=y, G[k].y=x, G[k].c=c;
}
for (i=1,ok=true;i<=k && ok;++i)
if (d[G[i].x]+G[i].c<d[G[i].y])
ok=false;
else
{
if (d[G[i].x]+G[i].c==d[G[i].y])
ap[G[i].y]=true;
}
for (i=1;i<=n && ok;++i)
if (!ap[i]) ok=false;
if (ok) g<<"DA\n";
else g<<"NU\n";
}
int main()
{
int i;
f>>t;
for (i=0;i<t;++i)
rez();
return 0;
}