Cod sursa(job #1909023)

Utilizator delta_wolfAndrei Stoica delta_wolf Data 7 martie 2017 11:25:19
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <cstdio>
#include <cstring>
#define MAXN 60001

using namespace std;
int t, ok, i;
long n, m, s, a[MAXN], x, y, c, j, sel[MAXN];

int main ()
{
    freopen("distante.in", "r", stdin);
  freopen("distante.out", "w", stdout);
  scanf("%d", &t);
  for (i=1; i<=t; i++)
    {
     memset(a, 0, sizeof(a));
     ok = 1;
     memset(sel, 0, sizeof(sel));
     scanf("%ld %ld %ld", &n, &m, &s);
     if (!m) ok = 0;
     for (j=1; j<=n; j++) scanf("%ld", &a[j]);
     for (j=1; j<=m; j++)
     {
        scanf("%ld %ld %ld", &x, &y, &c);
        if (a[x] + c == a[y]) sel[y] = 1;
        if (a[y] + c == a[x]) sel[x] = 1;
        if (a[x] + c < a[y] || a[y] + c < a[x]) ok = 0;
     }
     for (j=1; j<=n; j++) if ((!sel[j]) && (j!=s)) ok = 0;
     if (ok) printf("DA\n"); else printf("NU\n");
  }
    return 0;
}