Cod sursa(job #1043751)

Utilizator BogdySSSzekely Bogdan BogdySS Data 28 noiembrie 2013 22:03:32
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>
using namespace std;

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




int main()
{
    int t, n, m, s, v[50005], a, b, c;
    bool ok[50005];
    fin >> t;
    while(t--){
        fin >> n >> m >> s;
        for(int i=1;i<=n;i++){
            fin >> v[i];
            ok[i]=false;
        }

        while(m--){
            fin >> a >> b >> c;
            if(v[a]==v[b]+c)
                ok[a]=true;
            if(v[b]==v[a]+c)
                ok[b]=true;
        }
        if(v[s]==0)
            ok[s]=true;


        bool okfinal=true;
        for(int i=1;i<=n;i++)
            if(!ok[i]){
                okfinal=false;break;
            }
        if(okfinal)
            fout << "DA\n";
        else
            fout << "NU\n";

    }

    return 0;
}