Pagini recente » Cod sursa (job #1344014) | Cod sursa (job #2215375) | Cod sursa (job #1936669) | Cod sursa (job #1806592) | Cod sursa (job #451579)
Cod sursa(job #451579)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
int d[50001], gasit[50001];
int main()
{
freopen("distante.in", "r", stdin);
freopen("distante.out", "w", stdout);
int t, n, m, s, i, x, y, c, rez;
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d", &n, &m, &s);
for(i = 1; i <= n; ++i) scanf("%d", d + i), gasit[i] = 0;
gasit[s] = rez = 1;
if(d[s] != 0) rez = 0;
for(i = 1; i <= m; ++i)
{
scanf("%d%d%d", &x, &y, &c);
if(d[y] > d[x] + c) rez = 0;
if(d[x] > d[y] + c) rez = 0;
if(!gasit[y]) if(d[y] == d[x] + c) gasit[y] = 1;
if(!gasit[x]) if(d[x] == d[y] + c) gasit[x] = 1;
}
for(i = 1; i <= n && rez == 1; ++i) if(!gasit[i]) rez = 0;
if(rez) printf("DA\n");
else printf("NU\n");
}
return 0;
}