Cod sursa(job #1478613)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 29 august 2015 02:38:59
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMax = 50005;

int D[NMax];

int main(){
    int t, n, m, s, a, b, c;
    bool good;
    fin >> t;
    while(t--){
        fin >> n >> m >> s;
        good = true;
        for(int i = 1; i <= n; i++){
            fin >> D[i];
        }
        if(D[s]){
            good = false;
        }
        for(int i = 1; i <= m; i++){
            fin >> a >> b >> c;
            if(D[a] + c < D[b] || D[b] + c < D[a]){
                good = false;
            }
        }
        if(good){
            fout << "DA\n";
        } else {
            fout << "NU\n";
        }
    }
    return 0;
}