Cod sursa(job #1090138)

Utilizator MarghescuGabriel Marghescu Marghescu Data 22 ianuarie 2014 13:07:25
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <cstdio>
using namespace std;
int dist[50005];
int n,m,s,t;
int main()
{
    freopen("distante.in","r",stdin);
    freopen("distante.out","w",stdout);

    scanf("%d",&t);
    while (t--)
    {
        bool ok = false;
        scanf("%d %d %d",&n,&m,&s);
        for (int i=1;i<=n;i++)
            scanf("%d",&dist[i]);
        for (int i=1;i<=m;i++)
    {
            int a,b,d;
            scanf("%d %d %d",&a,&b,&d);

            if (dist[a] + d < dist[b])
                ok = true;
            if (dist[b] + d < dist[a])
                ok = true;
            if (dist[s] != 0)
                ok = true;
        }
        if (ok)
            printf("NU\n");
        else
            printf("DA\n");
    }
    return 0;
}