Cod sursa(job #1338615)

Utilizator tatianazTatiana Zapirtan tatianaz Data 10 februarie 2015 10:12:17
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 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 d[SIZE];

void Solve()
{
    is >> n >> m >> s;
    for ( int i = 1; i <= n; ++i )
        is >> d[i];

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

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

    }
}

int main()
{
    is >> t;
    for ( int i = 1; i <= t; ++i )
    {
        Solve();

        if ( d[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;
}