Cod sursa(job #1001403)

Utilizator cbanu96Banu Cristian cbanu96 Data 24 septembrie 2013 21:52:09
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <utility>

#define FILEIN "distante.in"
#define FILEOUT "distante.out"

using namespace std;

const int NMAX = 50005;
const int INF  = 0x3f3f3f3f;
int N, M, S;
int givenD[NMAX];


int main()
{
    freopen(FILEIN, "r", stdin);
    freopen(FILEOUT, "w", stdout);
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%d %d %d", &N, &M, &S);

        for ( int i = 1; i <= N; i++) {
            scanf("%d", &givenD[i]);
        }

        bool valid = true;

        for ( int i = 1, x, y, d; i <= M; i++) {
            scanf("%d %d %d", &x, &y, &d);
            if ( givenD[x] + d < givenD[y])
                valid = false;
            if ( givenD[y] + d < givenD[x])
                valid = false;
        }

        if(valid && givenD[S] == 0)
            printf("DA\n");
        else
            printf("NU\n");
    }

    return 0;
}