Cod sursa(job #911189)

Utilizator bocacristiBoca Nelu Cristian bocacristi Data 11 martie 2013 13:29:09
Problema Distante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
using namespace std;

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

int main()
{
    int t, n, m, s, v[50010];
    int x, y, z, vrf = 1;
    fin >> t;
    for ( ;t;--t)
    {
        fin >> n >> m >> s;
        for ( int i = 0; i <= n; ++i )
            fin >> v[i];
        if ( v[s] != 0 )
        {
            vrf = 0;
            while(m)
            {
                fin >> x >> y >> z;
                --m;
            }
        }
        else
        {
            while(m)
            {
                fin >> x >> y >> z;
                if ( v[x] > v[y]+z || v[y] > v[x]+z)
                    vrf = 0;
                --m;
            }
        }
        if ( vrf)
            fout << "DA" << '\n';
        else
            fout << "NU" << '\n';
    }
}