Cod sursa(job #1338827)

Utilizator Corina1997Todoran Ana-Corina Corina1997 Data 10 februarie 2015 13:40:00
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
using namespace std;

ifstream is("distante.in");
ofstream os("distante.out");

const int SIZE = 50001;

bool ok[SIZE], oke;
int n, m, s, t;
int x, y, cost;
int a[SIZE];

int main()
{
    is >> t;
    for ( int i = 1; i <= t; ++i )
    {
        is >> n >> m >> s;
        for ( int i = 1; i <= n; ++i )
            is >> a[i];

        oke = true;
        for ( int i = 1; i <= m; ++i )
        {
            is >> x >> y >> cost;

            if ( a[x] + cost < a[y] || a[y] + cost < a[x] )
                oke = false;
            if ( a[x] + cost == a[y] )
                ok[y] = true;
            if ( a[y] + cost == a[x] )
                ok[x] = true;

        }

        if ( a[s] )
            oke = false;

        for ( int j = 1; j <= n; ++j )
            if ( j != s && !ok[j] )
                oke = false;

        if ( oke )
            os << "DA\n";
        else
            os << "NU\n";
    }


    is.close();
    os.close();
    return 0;
}