Cod sursa(job #1130127)

Utilizator Alexghita96Ghita Alexandru Alexghita96 Data 28 februarie 2014 11:25:46
Problema Distante Scor 100
Compilator cpp Status done
Runda preoji2014_3_11_12 Marime 0.79 kb
#include <cstdio>

#define Nmax 50005

int N, M, T, S, Cost[Nmax], ok;

void Citire()
{
    scanf("%d %d %d", &N, &M, &S);
    for (int i = 1; i <= N; ++i)
        scanf("%d", &Cost[i]);
}

void Verificare()
{
    int x, y, c;
    ok = 1;
    if (Cost[S])
        ok = 0;
    for (int i = 1; i <= M; ++i)
    {
        scanf("%d %d %d", &x, &y, &c);
        if (Cost[x] + c < Cost[y])
            ok = 0;
        if (Cost[y] + c < Cost[x])
            ok = 0;
    }
    if (ok)
        printf("DA\n");
    else
        printf("NU\n");
}

int main()
{
    freopen("distante.in", "r", stdin);
    freopen("distante.out", "w", stdout);

    scanf("%d", &T);

    for (int i = 1; i <= T; ++i)
    {
        Citire();
        Verificare();
    }

    return 0;
}