Cod sursa(job #918588)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 18 martie 2013 23:50:25
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>

using namespace std;

#define Nmax 50001

char InFile[] = { "distante.in" };
char OutFile[] = { "distante.out" };

int D[Nmax];

int N, M, T, S, a, b, c;

void rezolva(){

    ifstream F(InFile);
    ofstream G(OutFile);

    F >> T;

    for(; T; T--){

        F >> N >> M >> S;

        for ( int i = 1; i <= N; i++ )
                F >> D[i];

        bool VAL = true;

        if ( D[S] )
            VAL = false;

        for(; M; M--){

            F >> a >> b >> c;

            if ( D[a] > D[b] + c || D[b] > D[a] + c )
                VAL = false;
        }

        if ( VAL == true )
            G << "DA\n";
        else
            G << "NU\n";
    }
}

int main(){

    rezolva();

    return 0;
}