Cod sursa(job #1128545)

Utilizator alexclpAlexandru Clapa alexclp Data 27 februarie 2014 17:35:47
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 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 = 1;

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

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

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

    return ok;
}

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

    for (;teste; teste--) {

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

    return 0;
}