Cod sursa(job #285668)
| Utilizator | Data | 22 martie 2009 20:23:27 | |
|---|---|---|---|
| Problema | Distante | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1 kb |
#include<stdio.h>
#define dim 50001
int T, N, M, X0;
int a[dim];
int main()
{
int i, j, ok, x, y, c, cont;
freopen("distante.in", "r", stdin);
freopen("distante.out", "w", stdout);
scanf("%d", &T);
while(T)
{
ok=1;
cont = 0;
scanf("%d %d %d", &N, &M, &X0);
for(i = 1; i <= N; i++)
scanf("%d", &a[i]);
for(i = 1; i <= M; i++)
{
scanf("%d %d %d", &x, &y, &c);
if(y != X0)
if( a[y] == ( a[x] + c) ) cont++;
if( ( a[x] + c) < a[y]) ok = 0;
}
if( a[X0] != 0 ) ok=0;
if( cont != ( N - 1) ) ok = 0;
if(ok) printf("DA \n");
else printf("NU \n");
T--;
}
return 0;
}
