Cod sursa(job #1128528)

Utilizator alexclpAlexandru Clapa alexclp Data 27 februarie 2014 17:32:13
Problema Distante Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int N = 50005;

int noduri, muchii, sursa;

int d[N];

bool corect()
{
    in >> noduri >> muchii >> sursa;

    for (int i = 1; i <= noduri; ++i) {
        in >> d[i];
    }

    bool ok = true;

    if (d[sursa] == 0) {
        ok = true;
    }

    for (int i = 1; i <= muchii; ++i) {
        int x, y, z;
        in >> x >> y >> z;

        if (ok and (d[x] + z < d[y] or d[y] + z < d[x])) {
            ok = false;
        }
    }

    return ok;
}

int main()
{
    int teste;
    in >> teste;

    for (;teste; teste--) {

        if (corect()) {
            out << "DA\n";
        } else {
            out << "NU\n";
        }
    }

    return 0;
}