Cod sursa(job #1479581)

Utilizator tudormaximTudor Maxim tudormaxim Data 31 august 2015 17:14:38
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std;
const int nmax = 50005;
int n, m, s, t, d[nmax], a, b, c;

int main()
{
    freopen("distante.in","r",stdin);
    freopen("distante.out","w",stdout);
     scanf("%d", &t);
     while(t--)
     {
         bool ok = true;
         scanf("%d %d %d", &n, &m, &s);
         for(int i=1; i<=n; i++)
            scanf("%d ", &d[i]);

         if (d[s]) ok = false;

         while(m--)
         {
             scanf("%d %d %d", &a, &b, &c);
             if(d[a] + c < d[b] || d[b] + c < d[a])
                ok = false;
         }
         if (ok) printf("DA\n");
        else printf("NU\n");
     }
     return 0;
}