Pagini recente » Cod sursa (job #971297) | Cod sursa (job #486068) | Cod sursa (job #876790) | Cod sursa (job #333496) | Cod sursa (job #1075095)
#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];
void rez()
{
int x,y,c,i;
bool ok;
f>>n>>m>>s;
for (i=1;i<=n;++i) f>>d[i];
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;
if (ok) g<<"DA\n";
else g<<"NU\n";
}
int main()
{
int i;
f>>t;
for (i=0;i<t;++i)
rez();
return 0;
}