Cod sursa(job #1393211)

Utilizator Toast97Calin Farcas Toast97 Data 19 martie 2015 10:38:46
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

using namespace std;

ifstream f ("distante.in");
ofstream g ("distante.out");

int D[50005];

int main()
{
    int t, a, b, c, n, m, s;
    bool ok;

    f >> t;

    for (int i = 1; i <= t; i ++)
    {
        f >> n >> m >> s;

        for (int j = 1; j <= n; j ++)
            f >> D[j];

        ok = 1;

        for (int j = 1; j <= m; j ++)
        {
            f >> a >> b >> c;

            if (D[a] + c < D[b] || D[b] + c < D[a])
                ok = 0;
        }

        if (D[s] != 0)
            ok = 0;

        if (ok)
            g << "DA\n";
        else
            g << "NU\n";

    }

    f.close ();
    g.close ();
    return 0;
}