Cod sursa(job #2358946)

Utilizator HerddexJinga Tudor Herddex Data 28 februarie 2019 14:49:18
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
const int maxN = 50001;

bool check_graph() {
    int N, M, S;
    bool ok = true;
    fin >> N >> M >> S;
    //check if distance of S is non zero
    int dist[maxN];
    for(int i=1; i<=N; i++)
        fin >> dist[i];
    if(dist[S] != 0)
        ok = false;

    for(; M; M--) {
        int a, b, c;
        fin >> a >> b >> c;
        if(dist[a] + c < dist[b])
            ok = false;
    }
    return ok;
}


int main() {

    int T;
    for(fin >> T; T; T--) {
        if(check_graph())
            fout << "DA\n";
        else
            fout << "NU\n";
    }

	fin.close();
	fout.close();
	return 0;
}